Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inbox files as iterable

Actually, the way to read the inbox queue of file names is by manually looping over `inbox.nextFile()` until it returns nothing.

That's already solved with iterables.
You can evolve that API to expose something like this:

const inboxFiles = {
  next: () => {
    const value = inbox.nextFile();
    return {
      value: value as string,
      done: !value,
    };
  },
  [Symbol.iterator]: function () {
    return this;
  },
};

So we can do stuff like

for (const fileName of inboxFiles) {
  doStuff(fileName);
}


compared to:

let fileName = inbox.nextFile();
while (fileName) {
  doStuff(fileName);
  fileName = inbox.nextFile(fileName);
}

 

Best Answer
0 Votes
0 REPLIES 0