Unsub from newHead snippet (#669)

This commit is contained in:
Jaco Greeff 2019-02-01 12:06:27 +01:00 committed by GitHub
parent 862a7c893e
commit 5df31ca256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
});`;