@polkadot/rpc-core 9.14.2 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,37 @@
1
- // Copyright 2017-2023 @polkadot/rpc-core authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  import { asapScheduler, Observable, Subscription } from 'rxjs';
5
-
6
2
  /** @internal */
7
3
  export function refCountDelay(delay = 1750) {
8
- return source => {
9
- // state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
10
- let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
11
- return new Observable(ob => {
12
- source.subscribe(ob);
13
- if (refCount++ === 0) {
14
- if (state === 1) {
15
- scheduler.unsubscribe();
16
- } else {
17
- // eslint-disable-next-line deprecation/deprecation
18
- connection = source.connect();
19
- }
20
- state = 3;
21
- }
22
- return () => {
23
- if (--refCount === 0) {
24
- if (state === 2) {
25
- state = 0;
26
- scheduler.unsubscribe();
27
- } else {
28
- // state === 3
29
- state = 1;
30
- scheduler = asapScheduler.schedule(() => {
31
- state = 0;
32
- connection.unsubscribe();
33
- }, delay);
34
- }
35
- }
36
- };
37
- });
38
- };
4
+ return (source) => {
5
+ // state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
6
+ let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
7
+ return new Observable((ob) => {
8
+ source.subscribe(ob);
9
+ if (refCount++ === 0) {
10
+ if (state === 1) {
11
+ scheduler.unsubscribe();
12
+ }
13
+ else {
14
+ // eslint-disable-next-line deprecation/deprecation
15
+ connection = source.connect();
16
+ }
17
+ state = 3;
18
+ }
19
+ return () => {
20
+ if (--refCount === 0) {
21
+ if (state === 2) {
22
+ state = 0;
23
+ scheduler.unsubscribe();
24
+ }
25
+ else {
26
+ // state === 3
27
+ state = 1;
28
+ scheduler = asapScheduler.schedule(() => {
29
+ state = 0;
30
+ connection.unsubscribe();
31
+ }, delay);
32
+ }
33
+ }
34
+ };
35
+ });
36
+ };
39
37
  }