Added unsubscribe return function to wsProvider.on() (#1780)
* Added unsubscribe return function to wsProvider.on() * Updated mocks, added noop to http provider
This commit is contained in:
@@ -84,8 +84,11 @@ export default class HttpProvider implements ProviderInterface {
|
||||
* @description HTTP Provider does not have 'on' emitters. WebSockets should be used instead.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): void {
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void {
|
||||
l.error('HTTP Provider does not have \'on\' emitters, use WebSockets instead');
|
||||
return (): void => {
|
||||
// noop
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,8 +104,11 @@ export default class Mock implements ProviderInterface {
|
||||
return true;
|
||||
}
|
||||
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): void {
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void {
|
||||
this.emitter.on(type, sub);
|
||||
return (): void => {
|
||||
this.emitter.removeListener(type, sub);
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
|
||||
@@ -47,7 +47,7 @@ export interface ProviderInterface {
|
||||
clone (): ProviderInterface;
|
||||
disconnect (): void;
|
||||
isConnected (): boolean;
|
||||
on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): void;
|
||||
on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void;
|
||||
send (method: string, params: any[]): Promise<any>;
|
||||
subscribe (type: string, method: string, params: any[], cb: ProviderInterfaceCallback): Promise<number>;
|
||||
unsubscribe (type: string, method: string, id: number): Promise<boolean>;
|
||||
|
||||
@@ -167,9 +167,13 @@ export default class WsProvider implements WSProviderInterface {
|
||||
* @summary Listens on events after having subscribed using the [[subscribe]] function.
|
||||
* @param {ProviderInterfaceEmitted} type Event
|
||||
* @param {ProviderInterfaceEmitCb} sub Callback
|
||||
* @return unsubscribe function
|
||||
*/
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): void {
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void {
|
||||
this._eventemitter.on(type, sub);
|
||||
return (): void => {
|
||||
this._eventemitter.removeListener(type, sub);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user