From 44cdf49b2c41ae2f7d14b7cbf978423bb883a45d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 2 Jun 2020 17:14:29 +0200 Subject: [PATCH] Resolve first result after unsub promise (via setImmediate) (#2324) --- CHANGELOG.md | 4 ++ lerna.json | 2 +- package.json | 2 +- packages/api-contract/package.json | 8 ++-- packages/api-derive/package.json | 10 ++--- packages/api/package.json | 14 +++---- packages/api/src/promise/Api.ts | 10 ++++- packages/metadata/package.json | 6 +-- packages/rpc-core/package.json | 8 ++-- packages/rpc-provider/package.json | 6 +-- packages/typegen/package.json | 10 ++--- packages/types-known/package.json | 4 +- packages/types/package.json | 4 +- yarn.lock | 66 +++++++++++++++--------------- 14 files changed, 83 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e8b5d1d8..b9c2080639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.17.2 Jun 2, 2020 + +- Ensure subscription promise resolves before first result + ## 1.17.1 Jun 2, 2020 - Fix `ElectionSize` type (Thanks to https://github.com/arjanz) diff --git a/lerna.json b/lerna.json index 6d011bc54e..8a3aa29c31 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "1.17.1" + "version": "1.17.2" } diff --git a/package.json b/package.json index 6c6dedeeb9..6ffcd494bc 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,5 @@ "@vuepress/plugin-search": "^1.5.0", "copyfiles": "^2.3.0" }, - "version": "1.17.1" + "version": "1.17.2" } diff --git a/packages/api-contract/package.json b/packages/api-contract/package.json index fe06bc3e7b..f3bf49d0b9 100644 --- a/packages/api-contract/package.json +++ b/packages/api-contract/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/api-contract", - "version": "1.17.1", + "version": "1.17.2", "description": "Interfaces for interacting with contracts and contract ABIs", "main": "index.js", "keywords": [ @@ -27,9 +27,9 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/api": "1.17.1", - "@polkadot/rpc-core": "1.17.1", - "@polkadot/types": "1.17.1", + "@polkadot/api": "1.17.2", + "@polkadot/rpc-core": "1.17.2", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "bn.js": "^5.1.2", "rxjs": "^6.5.5" diff --git a/packages/api-derive/package.json b/packages/api-derive/package.json index eed605a842..881d76b678 100644 --- a/packages/api-derive/package.json +++ b/packages/api-derive/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/api-derive", - "version": "1.17.1", + "version": "1.17.2", "description": "Common functions used across Polkadot, derived from RPC calls and storage queries.", "main": "index.js", "keywords": [ @@ -28,10 +28,10 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/api": "1.17.1", - "@polkadot/rpc-core": "1.17.1", - "@polkadot/rpc-provider": "1.17.1", - "@polkadot/types": "1.17.1", + "@polkadot/api": "1.17.2", + "@polkadot/rpc-core": "1.17.2", + "@polkadot/rpc-provider": "1.17.2", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "@polkadot/util-crypto": "^2.12.2", "bn.js": "^5.1.2", diff --git a/packages/api/package.json b/packages/api/package.json index c5a93507d5..d6c6d9f027 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/api", - "version": "1.17.1", + "version": "1.17.2", "description": "Promise and RxJS wrappers around the Polkadot JS RPC", "main": "index.js", "keywords": [ @@ -27,13 +27,13 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/api-derive": "1.17.1", + "@polkadot/api-derive": "1.17.2", "@polkadot/keyring": "^2.12.2", - "@polkadot/metadata": "1.17.1", - "@polkadot/rpc-core": "1.17.1", - "@polkadot/rpc-provider": "1.17.1", - "@polkadot/types": "1.17.1", - "@polkadot/types-known": "1.17.1", + "@polkadot/metadata": "1.17.2", + "@polkadot/rpc-core": "1.17.2", + "@polkadot/rpc-provider": "1.17.2", + "@polkadot/types": "1.17.2", + "@polkadot/types-known": "1.17.2", "@polkadot/util": "^2.12.2", "@polkadot/util-crypto": "^2.12.2", "bn.js": "^5.1.2", diff --git a/packages/api/src/promise/Api.ts b/packages/api/src/promise/Api.ts index 38aa881ec2..fbf3e82ea5 100644 --- a/packages/api/src/promise/Api.ts +++ b/packages/api/src/promise/Api.ts @@ -84,7 +84,15 @@ export function decorateMethod (method: Method, opti // upon the first result, resolve with the unsub function // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return tap(() => tracker.resolve(() => subscription.unsubscribe())) - ).subscribe(callback); + ).subscribe((result: any): void => { + if (setImmediate) { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + setImmediate(() => callback(result) as void); + } else { + // eslint-disable-next-line @typescript-eslint/no-floating-promises + callback(result); + } + }); }) as UnsubscribePromise; } as StorageEntryPromiseOverloads; } diff --git a/packages/metadata/package.json b/packages/metadata/package.json index c71e33b3cc..8b31894a08 100644 --- a/packages/metadata/package.json +++ b/packages/metadata/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/metadata", - "version": "1.17.1", + "version": "1.17.2", "description": "Helpers to extract information from runtime metadata", "main": "index.js", "publishConfig": { @@ -27,8 +27,8 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/types": "1.17.1", - "@polkadot/types-known": "1.17.1", + "@polkadot/types": "1.17.2", + "@polkadot/types-known": "1.17.2", "@polkadot/util": "^2.12.2", "@polkadot/util-crypto": "^2.12.2", "bn.js": "^5.1.2" diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 2a3464367b..effdc0deac 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/rpc-core", - "version": "1.17.1", + "version": "1.17.2", "description": "A JavaScript wrapper for the Polkadot JsonRPC interface", "main": "index.js", "keywords": [ @@ -27,9 +27,9 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/metadata": "1.17.1", - "@polkadot/rpc-provider": "1.17.1", - "@polkadot/types": "1.17.1", + "@polkadot/metadata": "1.17.2", + "@polkadot/rpc-provider": "1.17.2", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "memoizee": "^0.4.14", "rxjs": "^6.5.5" diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 62613bc498..951a78ad20 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/rpc-provider", - "version": "1.17.1", + "version": "1.17.2", "description": "Transport providers for the API", "main": "index.js", "keywords": [ @@ -27,8 +27,8 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/metadata": "1.17.1", - "@polkadot/types": "1.17.1", + "@polkadot/metadata": "1.17.2", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "@polkadot/util-crypto": "^2.12.2", "bn.js": "^5.1.2", diff --git a/packages/typegen/package.json b/packages/typegen/package.json index b42c01a85b..20a0515b8c 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/typegen", - "version": "1.17.1", + "version": "1.17.2", "description": "Type generation scripts", "main": "index.js", "bin": { @@ -36,10 +36,10 @@ "@babel/core": "^7.10.2", "@babel/register": "^7.10.1", "@babel/runtime": "^7.10.2", - "@polkadot/api": "1.17.1", - "@polkadot/metadata": "1.17.1", - "@polkadot/rpc-provider": "1.17.1", - "@polkadot/types": "1.17.1", + "@polkadot/api": "1.17.2", + "@polkadot/metadata": "1.17.2", + "@polkadot/rpc-provider": "1.17.2", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "handlebars": "^4.7.6", "websocket": "^1.0.31", diff --git a/packages/types-known/package.json b/packages/types-known/package.json index 3a5f527550..f2b03f37bb 100644 --- a/packages/types-known/package.json +++ b/packages/types-known/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/types-known", - "version": "1.17.1", + "version": "1.17.2", "description": "A JavaScript wrapper for the Polkadot JsonRPC interface", "main": "index.js", "keywords": [ @@ -27,7 +27,7 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/types": "1.17.1", + "@polkadot/types": "1.17.2", "@polkadot/util": "^2.12.2", "bn.js": "^5.1.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index d08c2f014d..2e02c0eb57 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/types", - "version": "1.17.1", + "version": "1.17.2", "description": "Implementation of the Parity codec", "main": "index.js", "keywords": [ @@ -27,7 +27,7 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme", "dependencies": { "@babel/runtime": "^7.10.2", - "@polkadot/metadata": "1.17.1", + "@polkadot/metadata": "1.17.2", "@polkadot/util": "^2.12.2", "@polkadot/util-crypto": "^2.12.2", "@types/bn.js": "^4.11.6", diff --git a/yarn.lock b/yarn.lock index a0af1d99b1..9b64890df4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2669,25 +2669,25 @@ __metadata: resolution: "@polkadot/api-contract@workspace:packages/api-contract" dependencies: "@babel/runtime": ^7.10.2 - "@polkadot/api": 1.17.1 - "@polkadot/rpc-core": 1.17.1 - "@polkadot/types": 1.17.1 + "@polkadot/api": 1.17.2 + "@polkadot/rpc-core": 1.17.2 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 bn.js: ^5.1.2 rxjs: ^6.5.5 languageName: unknown linkType: soft -"@polkadot/api-derive@1.17.1, @polkadot/api-derive@workspace:packages/api-derive": +"@polkadot/api-derive@1.17.2, @polkadot/api-derive@workspace:packages/api-derive": version: 0.0.0-use.local resolution: "@polkadot/api-derive@workspace:packages/api-derive" dependencies: "@babel/runtime": ^7.10.2 - "@polkadot/api": 1.17.1 + "@polkadot/api": 1.17.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/rpc-core": 1.17.1 - "@polkadot/rpc-provider": 1.17.1 - "@polkadot/types": 1.17.1 + "@polkadot/rpc-core": 1.17.2 + "@polkadot/rpc-provider": 1.17.2 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 "@polkadot/util-crypto": ^2.12.2 bn.js: ^5.1.2 @@ -2696,18 +2696,18 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/api@1.17.1, @polkadot/api@workspace:packages/api": +"@polkadot/api@1.17.2, @polkadot/api@workspace:packages/api": version: 0.0.0-use.local resolution: "@polkadot/api@workspace:packages/api" dependencies: "@babel/runtime": ^7.10.2 - "@polkadot/api-derive": 1.17.1 + "@polkadot/api-derive": 1.17.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/metadata": 1.17.1 - "@polkadot/rpc-core": 1.17.1 - "@polkadot/rpc-provider": 1.17.1 - "@polkadot/types": 1.17.1 - "@polkadot/types-known": 1.17.1 + "@polkadot/metadata": 1.17.2 + "@polkadot/rpc-core": 1.17.2 + "@polkadot/rpc-provider": 1.17.2 + "@polkadot/types": 1.17.2 + "@polkadot/types-known": 1.17.2 "@polkadot/util": ^2.12.2 "@polkadot/util-crypto": ^2.12.2 bn.js: ^5.1.2 @@ -2816,43 +2816,43 @@ __metadata: languageName: node linkType: hard -"@polkadot/metadata@1.17.1, @polkadot/metadata@workspace:packages/metadata": +"@polkadot/metadata@1.17.2, @polkadot/metadata@workspace:packages/metadata": version: 0.0.0-use.local resolution: "@polkadot/metadata@workspace:packages/metadata" dependencies: "@babel/runtime": ^7.10.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/types": 1.17.1 - "@polkadot/types-known": 1.17.1 + "@polkadot/types": 1.17.2 + "@polkadot/types-known": 1.17.2 "@polkadot/util": ^2.12.2 "@polkadot/util-crypto": ^2.12.2 bn.js: ^5.1.2 languageName: unknown linkType: soft -"@polkadot/rpc-core@1.17.1, @polkadot/rpc-core@workspace:packages/rpc-core": +"@polkadot/rpc-core@1.17.2, @polkadot/rpc-core@workspace:packages/rpc-core": version: 0.0.0-use.local resolution: "@polkadot/rpc-core@workspace:packages/rpc-core" dependencies: "@babel/runtime": ^7.10.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/metadata": 1.17.1 - "@polkadot/rpc-provider": 1.17.1 - "@polkadot/types": 1.17.1 + "@polkadot/metadata": 1.17.2 + "@polkadot/rpc-provider": 1.17.2 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 memoizee: ^0.4.14 rxjs: ^6.5.5 languageName: unknown linkType: soft -"@polkadot/rpc-provider@1.17.1, @polkadot/rpc-provider@workspace:packages/rpc-provider": +"@polkadot/rpc-provider@1.17.2, @polkadot/rpc-provider@workspace:packages/rpc-provider": version: 0.0.0-use.local resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider" dependencies: "@babel/runtime": ^7.10.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/metadata": 1.17.1 - "@polkadot/types": 1.17.1 + "@polkadot/metadata": 1.17.2 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 "@polkadot/util-crypto": ^2.12.2 bn.js: ^5.1.2 @@ -2880,10 +2880,10 @@ __metadata: "@babel/core": ^7.10.2 "@babel/register": ^7.10.1 "@babel/runtime": ^7.10.2 - "@polkadot/api": 1.17.1 - "@polkadot/metadata": 1.17.1 - "@polkadot/rpc-provider": 1.17.1 - "@polkadot/types": 1.17.1 + "@polkadot/api": 1.17.2 + "@polkadot/metadata": 1.17.2 + "@polkadot/rpc-provider": 1.17.2 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 "@types/websocket": ^1.0.0 "@types/yargs": ^15.0.5 @@ -2899,25 +2899,25 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/types-known@1.17.1, @polkadot/types-known@workspace:packages/types-known": +"@polkadot/types-known@1.17.2, @polkadot/types-known@workspace:packages/types-known": version: 0.0.0-use.local resolution: "@polkadot/types-known@workspace:packages/types-known" dependencies: "@babel/runtime": ^7.10.2 - "@polkadot/types": 1.17.1 + "@polkadot/types": 1.17.2 "@polkadot/util": ^2.12.2 "@types/bn.js": ^4.11.6 bn.js: ^5.1.2 languageName: unknown linkType: soft -"@polkadot/types@1.17.1, @polkadot/types@workspace:packages/types": +"@polkadot/types@1.17.2, @polkadot/types@workspace:packages/types": version: 0.0.0-use.local resolution: "@polkadot/types@workspace:packages/types" dependencies: "@babel/runtime": ^7.10.2 "@polkadot/keyring": ^2.12.2 - "@polkadot/metadata": 1.17.1 + "@polkadot/metadata": 1.17.2 "@polkadot/util": ^2.12.2 "@polkadot/util-crypto": ^2.12.2 "@types/bn.js": ^4.11.6