git.delta.rocks / unique-network / refs/commits / f663e99db821

difftreelog

source

tests/src/substrate/wait-new-blocks.ts590 Bsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {ApiPromise} from '@polkadot/api';78/* eslint no-async-promise-executor: "off" */9export default function waitNewBlocks(api: ApiPromise, blocksCount = 1): Promise<void> {10  const promise = new Promise<void>(async (resolve) => {1112    const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {13      if (blocksCount > 0) {14        blocksCount--;15      } else {16        unsubscribe();17        resolve();18      }19    });20  });2122  return promise;23}