1 | // Copyright 2017-2018 @polkadot/api-provider authors & contributors
|
2 | // This software may be modified and distributed under the terms
|
3 | // of the ISC license. See the LICENSE file for details.
|
4 |
|
5 | import { MockState } from './types';
|
6 |
|
7 | export default async function unsubscribe (self: MockState, type: string, name: string, id: number): Promise<boolean> {
|
8 | const method = self.subscriptionMap[id];
|
9 |
|
10 | self.l.debug(() => ['unsubscribe', id, method]);
|
11 |
|
12 | if (!method) {
|
13 | throw new Error(`Unable to find subscription for ${id}`);
|
14 | }
|
15 |
|
16 | delete self.subscriptionMap[id];
|
17 | delete self.subscriptions[method].callbacks[id];
|
18 |
|
19 | return true;
|
20 | }
|