Skip to content

Commit 44cdf49

Browse files
authored
Resolve first result after unsub promise (via setImmediate) (#2324)
1 parent daaf465 commit 44cdf49

File tree

14 files changed

+83
-71
lines changed

14 files changed

+83
-71
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.17.2 Jun 2, 2020
4+
5+
- Ensure subscription promise resolves before first result
6+
37
## 1.17.1 Jun 2, 2020
48

59
- Fix `ElectionSize` type (Thanks to https://github.com/arjanz)

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"packages": [
1010
"packages/*"
1111
],
12-
"version": "1.17.1"
12+
"version": "1.17.2"
1313
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
"@vuepress/plugin-search": "^1.5.0",
3535
"copyfiles": "^2.3.0"
3636
},
37-
"version": "1.17.1"
37+
"version": "1.17.2"
3838
}

packages/api-contract/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/api-contract",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "Interfaces for interacting with contracts and contract ABIs",
55
"main": "index.js",
66
"keywords": [
@@ -27,9 +27,9 @@
2727
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
2828
"dependencies": {
2929
"@babel/runtime": "^7.10.2",
30-
"@polkadot/api": "1.17.1",
31-
"@polkadot/rpc-core": "1.17.1",
32-
"@polkadot/types": "1.17.1",
30+
"@polkadot/api": "1.17.2",
31+
"@polkadot/rpc-core": "1.17.2",
32+
"@polkadot/types": "1.17.2",
3333
"@polkadot/util": "^2.12.2",
3434
"bn.js": "^5.1.2",
3535
"rxjs": "^6.5.5"

packages/api-derive/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/api-derive",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
55
"main": "index.js",
66
"keywords": [
@@ -28,10 +28,10 @@
2828
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
2929
"dependencies": {
3030
"@babel/runtime": "^7.10.2",
31-
"@polkadot/api": "1.17.1",
32-
"@polkadot/rpc-core": "1.17.1",
33-
"@polkadot/rpc-provider": "1.17.1",
34-
"@polkadot/types": "1.17.1",
31+
"@polkadot/api": "1.17.2",
32+
"@polkadot/rpc-core": "1.17.2",
33+
"@polkadot/rpc-provider": "1.17.2",
34+
"@polkadot/types": "1.17.2",
3535
"@polkadot/util": "^2.12.2",
3636
"@polkadot/util-crypto": "^2.12.2",
3737
"bn.js": "^5.1.2",

packages/api/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/api",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
55
"main": "index.js",
66
"keywords": [
@@ -27,13 +27,13 @@
2727
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
2828
"dependencies": {
2929
"@babel/runtime": "^7.10.2",
30-
"@polkadot/api-derive": "1.17.1",
30+
"@polkadot/api-derive": "1.17.2",
3131
"@polkadot/keyring": "^2.12.2",
32-
"@polkadot/metadata": "1.17.1",
33-
"@polkadot/rpc-core": "1.17.1",
34-
"@polkadot/rpc-provider": "1.17.1",
35-
"@polkadot/types": "1.17.1",
36-
"@polkadot/types-known": "1.17.1",
32+
"@polkadot/metadata": "1.17.2",
33+
"@polkadot/rpc-core": "1.17.2",
34+
"@polkadot/rpc-provider": "1.17.2",
35+
"@polkadot/types": "1.17.2",
36+
"@polkadot/types-known": "1.17.2",
3737
"@polkadot/util": "^2.12.2",
3838
"@polkadot/util-crypto": "^2.12.2",
3939
"bn.js": "^5.1.2",

packages/api/src/promise/Api.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ export function decorateMethod<Method extends AnyFunction> (method: Method, opti
8484
// upon the first result, resolve with the unsub function
8585
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
8686
tap(() => tracker.resolve(() => subscription.unsubscribe()))
87-
).subscribe(callback);
87+
).subscribe((result: any): void => {
88+
if (setImmediate) {
89+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
90+
setImmediate(() => callback(result) as void);
91+
} else {
92+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
93+
callback(result);
94+
}
95+
});
8896
}) as UnsubscribePromise;
8997
} as StorageEntryPromiseOverloads;
9098
}

packages/metadata/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/metadata",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "Helpers to extract information from runtime metadata",
55
"main": "index.js",
66
"publishConfig": {
@@ -27,8 +27,8 @@
2727
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
2828
"dependencies": {
2929
"@babel/runtime": "^7.10.2",
30-
"@polkadot/types": "1.17.1",
31-
"@polkadot/types-known": "1.17.1",
30+
"@polkadot/types": "1.17.2",
31+
"@polkadot/types-known": "1.17.2",
3232
"@polkadot/util": "^2.12.2",
3333
"@polkadot/util-crypto": "^2.12.2",
3434
"bn.js": "^5.1.2"

packages/rpc-core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/rpc-core",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
55
"main": "index.js",
66
"keywords": [
@@ -27,9 +27,9 @@
2727
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
2828
"dependencies": {
2929
"@babel/runtime": "^7.10.2",
30-
"@polkadot/metadata": "1.17.1",
31-
"@polkadot/rpc-provider": "1.17.1",
32-
"@polkadot/types": "1.17.1",
30+
"@polkadot/metadata": "1.17.2",
31+
"@polkadot/rpc-provider": "1.17.2",
32+
"@polkadot/types": "1.17.2",
3333
"@polkadot/util": "^2.12.2",
3434
"memoizee": "^0.4.14",
3535
"rxjs": "^6.5.5"

packages/rpc-provider/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot/rpc-provider",
3-
"version": "1.17.1",
3+
"version": "1.17.2",
44
"description": "Transport providers for the API",
55
"main": "index.js",
66
"keywords": [
@@ -27,8 +27,8 @@
2727
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
2828
"dependencies": {
2929
"@babel/runtime": "^7.10.2",
30-
"@polkadot/metadata": "1.17.1",
31-
"@polkadot/types": "1.17.1",
30+
"@polkadot/metadata": "1.17.2",
31+
"@polkadot/types": "1.17.2",
3232
"@polkadot/util": "^2.12.2",
3333
"@polkadot/util-crypto": "^2.12.2",
3434
"bn.js": "^5.1.2",

0 commit comments

Comments
 (0)