UNPKG

689 BJavaScriptView Raw
1"use strict";
2
3// Copyright 2017-2018 Jaco Greeff
4// This software may be modified and distributed under the terms
5// of the ISC license. See the LICENSE file for details.
6module.exports = async function subscribe(self, method, params) {
7 self.l.debug(() => ['subscribe', method, params]);
8
9 if (self.subscriptions[method]) {
10 // flowlint-next-line unclear-type:off
11 const callback = params.pop();
12 const id = ++self.subscriptionId;
13 self.subscriptions[method].callbacks[id] = callback;
14 self.subscriptionMap[id] = method;
15 callback(null, self.subscriptions[method].lastValue);
16 return id;
17 }
18
19 throw new Error(`provider.subscribe: Invalid method '${method}'`);
20};
\No newline at end of file