UNPKG

@polkadot/api-provider

Version:
24 lines (20 loc) 763 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = subscribe; // Copyright 2017-2018 @polkadot/api-provider authors & contributors // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. async function subscribe(self, type, method, params) { self.l.debug(() => ['subscribe', method, params]); if (self.subscriptions[method]) { const callback = params.pop(); const id = ++self.subscriptionId; self.subscriptions[method].callbacks[id] = callback; self.subscriptionMap[id] = method; callback(null, self.subscriptions[method].lastValue); return id; } throw new Error(`provider.subscribe: Invalid method '${method}'`); }