From d6f180cf361a95d4d4fbf1f4ddd3bb663970aeff Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 5 Oct 2021 13:35:29 +1100 Subject: [PATCH] Use callback option in store guide --- guides/store-retrieve-messages.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/guides/store-retrieve-messages.md b/guides/store-retrieve-messages.md index dbab771cbd..ffefff452b 100644 --- a/guides/store-retrieve-messages.md +++ b/guides/store-retrieve-messages.md @@ -140,23 +140,26 @@ const decodeWakuMessage = (wakuMessage) => { You now have all the building blocks to retrieve and decode messages for a store node. -Retrieve messages from a store node: +Store node responses are paginated. +The `WakuStore.queryHistory` API automatically query all the pages in a sequential manner. +To process messages as soon as they received (page by page), use the `callback` option: ```js const ContentTopic = '/store-guide/1/news/proto'; waku.store - .queryHistory([ContentTopic]) + .queryHistory([ContentTopic], { + callback: (retrievedMessages) => { + const articles = retrievedMessages + .map(decodeWakuMessage) // Decode messages + .filter(Boolean); // Filter out undefined values + + console.log(`${articles.length} articles have been retrieved`); + } + }) .catch((e) => { // Be sure to catch any potential error console.log('Failed to retrieve messages', e); - }) - .then((retrievedMessages) => { - const articles = retrievedMessages - .map(decodeWakuMessage) // Decode messages - .filter(Boolean); // Filter out undefined values - - console.log(`${articles.length} articles have been retrieved`); }); ```