Skip to content

Commit

Permalink
update message generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jobisoft committed Nov 29, 2023
1 parent f4eb296 commit 45631d5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions how-to/messageLists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Working with Message Lists

Mail folders could contain a *lot* of messages: thousands, tens of thousands, or even hundreds of thousands.

It would be a very bad idea to deal with that many messages at once, so the WebExtensions APIs split any response that could contain many messages into pages (or chunks, or groups, or whatever…). The default size of each page is 100 messages, although this could change and you **must not** rely on that number.
It would be a very bad idea to deal with that many messages at once, so the WebExtensions APIs split any response that could contain many messages into pages (or chunks). The default size of each page is 100 messages, although this could change and you **must not** rely on that number.

Each page is an object with two properties: ``id``, and ``messages``. To get the next page, call :ref:`messages.continueList` with the ``id`` property as an argument:

Expand All @@ -22,8 +22,8 @@ You could also wrap this code in a generator for ease-of-use:

.. code-block:: javascript
async function* listMessages(folder) {
let page = await messenger.messages.list(folder);
async function* getMessages(list) {
let page = await list;
for (let message of page.messages) {
yield message;
}
Expand All @@ -36,7 +36,7 @@ You could also wrap this code in a generator for ease-of-use:
}
}
let messages = listMessages(folder);
let messages = getMessages(messenger.messages.list(folder));
for await (let message of messages) {
// Do something with the message.
let full = await messenger.messages.getFull(message.id);
Expand Down

0 comments on commit 45631d5

Please sign in to comment.