@wpkernel/pipeline / processSequentially
Function: processSequentially()
function processSequentially<T>(
items,
handler,
direction): MaybePromise<void>;Processes items in order without promoting an entirely synchronous traversal to a promise.
Synchronous handlers run in the current call stack. After the first thenable result, later items run only after that result settles. Each handler result crosses the shared read-once thenable boundary. A synchronous throw or throwing then getter stops traversal synchronously; after promotion, a failure rejects the returned native promise and no later item is admitted.
Type Parameters
T
T
Parameters
items
readonly T[]
Ordered items to visit.
handler
(item, index) => MaybePromise<void>
Operation invoked once for each admitted item.
direction
Whether to visit from the first item or the last.
"forward" | "reverse"
Returns
MaybePromise<void>
void for a synchronous traversal, or a native promise after asynchronous promotion.
Example
const visited: number[] = [];
const result = processSequentially([1, 2], (value) => {
visited.push(value);
});
isPromiseLike(result); // false