Expose WS subscribe/unsubscribe (#63)

* Expose WS subscribe

* Support unsubscribe

* Align unsubscribe with method

* Basic e2e sub test

* Cleanup parameter positions

* Small update

* Handle non-supplied in output formatter
This commit is contained in:
Jaco Greeff
2018-04-16 13:49:02 +02:00
committed by GitHub
parent 232cd11e9d
commit 462fa6e5c4
26 changed files with 427 additions and 83 deletions
+14 -2
View File
@@ -5,6 +5,18 @@
import type { WsState } from './types';
module.exports = async function unsubscribe (self: WsState, id: number): Promise<boolean> {
throw new Error('Subscriptions has not been implemented');
const assert = require('@polkadot/util/assert');
const isUndefined = require('@polkadot/util/is/undefined');
const send = require('./send');
module.exports = async function unsubscribe (self: WsState, method: string, id: number): Promise<boolean> {
assert(!isUndefined(self.subscriptions[id]), `Unable to find active subscription=${id}`);
delete self.subscriptions[id];
const result = await send(self, method, [id]);
// flowlint-next-line unclear-type:off
return ((result: any): boolean);
};