@@ -623,6 +623,9 @@ const R = (...a) => new Revocable(...a);
623
623
// Min(-2) waits until an Acquire
624
624
// .Waiting(N) wait until .wait <= N
625
625
//
626
+ // .fifo() switches in FiFo-queuing-strategy (first in, first out), default
627
+ // .lifo() switches in LiFo-queuing-strategy (last in, first out)
628
+ //
626
629
// 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.
627
630
// If it returns a Promise, execution halts until the Promise resolves. If it rejects or .max() throws, this is as if it returns 1
628
631
// .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) =>
832
835
}
833
836
const Acquire = async ( ...a ) => release_function ( await Free ( ...a ) ) ;
834
837
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 ; } ;
836
843
ret . max = max ;
837
844
ret . fn = fn ;
838
845
ret . args = args ;
0 commit comments