Skip to content

Commit 225b44c

Browse files
committed
es13.js modified
1 parent 61aceb6 commit 225b44c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

es13.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ const R = (...a) => new Revocable(...a);
623623
// Min(-2) waits until an Acquire
624624
// .Waiting(N) wait until .wait <= N
625625
//
626+
// .fifo() switches in FiFo-queuing-strategy (first in, first out), default
627+
// .lifo() switches in LiFo-queuing-strategy (last in, first out)
628+
//
626629
// If .max is a function, it is called with the Semaphore (and optional .Acquire() args) can dynamically return how much work to do in parallel.
627630
// If it returns a Promise, execution halts until the Promise resolves. If it rejects or .max() throws, this is as if it returns 1
628631
// .max() is always called when something happens on the Semaphore (work added, finished, etc.), so it can be used to implement progress monitoring.
@@ -832,7 +835,11 @@ const Semaphore = (max, fn, ...args) =>
832835
}
833836
const Acquire = async (...a) => release_function(await Free(...a));
834837

835-
const ret = (..._) => next(new Promise((ok,ko) => waits.push([ok,ko,_])).then(() => (ret.fn ? ret.fn : (...a)=>a)(...ret.args,..._)).finally(() => next(upd(-1))));
838+
let discipline = 'push';
839+
840+
const ret = (..._) => next(new Promise((ok,ko) => waits[discipline]([ok,ko,_])).then(() => (ret.fn ? ret.fn : (...a)=>a)(...ret.args,..._)).finally(() => next(upd(-1))));
841+
ret.lifo = () => { discipline='unshift'; return ret; };
842+
ret.fifo = () => { discipline='push'; return ret; };
836843
ret.max = max;
837844
ret.fn = fn;
838845
ret.args = args;

0 commit comments

Comments
 (0)