Unsub from newHead snippet (#669)
This commit is contained in:
parent
862a7c893e
commit
5df31ca256
@ -2,7 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export default `// subscribe to new headers, printing the full result
|
||||
api.rpc.chain.subscribeNewHead((header) => {
|
||||
export default `// subscribe to new headers, printing the full info for 5
|
||||
let count = 0;
|
||||
const unsub = await api.rpc.chain.subscribeNewHead((header) => {
|
||||
console.log(\`#\${header.blockNumber}:\`, header);
|
||||
|
||||
if (++count === 5) {
|
||||
console.log('5 headers retrieved, unsubscribing');
|
||||
unsub();
|
||||
}
|
||||
});`;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user