Multi doc usage with unsub (#1088)

* Multi doc usage with unsub

* Remove double multiUnsub()

* Typing for promise multi

* Missing await
This commit is contained in:
Jaco Greeff
2019-07-09 15:44:28 +02:00
committed by GitHub
parent efeedf09af
commit 70dadb8304
3 changed files with 19 additions and 2 deletions
+3 -1
View File
@@ -247,7 +247,7 @@ export default abstract class ApiBase<ApiType> {
* <BR>
*
* ```javascript
* api.queryMulti(
* const unsub = await api.queryMulti(
* [
* // you can include the storage without any parameters
* api.query.balances.totalIssuance,
@@ -256,6 +256,8 @@ export default abstract class ApiBase<ApiType> {
* ],
* ([existential, balance]) => {
* console.log(`You have ${balance.sub(existential)} more than the existential deposit`);
*
* unsub();
* }
* );
* ```
+10
View File
@@ -19,6 +19,16 @@ export default async function test () {
const intentions = await api.query.staking.intentions();
console.log('intentions:', intentions);
// check multi for unsub
const multiUnsub = await api.queryMulti([
[api.query.system.accountNonce, keyring.eve.address],
[api.query.system.accountNonce, keyring.bob.address]
], (balances) => {
console.log('balances', balances);
multiUnsub();
});
await api.query.staking.intentions((intentions) => {
console.log('intentions:', intentions);
});
+6 -1
View File
@@ -107,12 +107,17 @@ export interface StorageEntryPromiseOverloads {
<T extends Codec>(arg1: CodecArg, arg2: CodecArg, callback: Callback<T>): UnsubscribePromise;
}
export interface StorageEntryPromiseMulti {
<T extends Codec>(args: Array<CodecArg[] | CodecArg>): Promise<Array<T>>;
<T extends Codec>(args: Array<CodecArg[] | CodecArg>, callback: Callback<Array<T>>): UnsubscribePromise;
}
export interface StorageEntryPromise extends StorageEntryPromiseOverloads {
at: (hash: Hash | Uint8Array | string, arg1?: CodecArg, arg2?: CodecArg) => Promise<Codec>;
creator: StorageEntry;
hash: (arg1?: CodecArg, arg2?: CodecArg) => Promise<Hash>;
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
multi: <T extends Codec>(args: Array<CodecArg[] | CodecArg>, callback?: Callback<Array<T>>) => Promise<Array<T>>;
multi: StorageEntryPromiseMulti;
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<U64>;
}