UNPKG

763 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = subscribe;
7
8// Copyright 2017-2018 @polkadot/api-provider authors & contributors
9// This software may be modified and distributed under the terms
10// of the ISC license. See the LICENSE file for details.
11async function subscribe(self, type, method, params) {
12 self.l.debug(() => ['subscribe', method, params]);
13
14 if (self.subscriptions[method]) {
15 const callback = params.pop();
16 const id = ++self.subscriptionId;
17 self.subscriptions[method].callbacks[id] = callback;
18 self.subscriptionMap[id] = method;
19 callback(null, self.subscriptions[method].lastValue);
20 return id;
21 }
22
23 throw new Error(`provider.subscribe: Invalid method '${method}'`);
24}
\No newline at end of file