How do I write a method that limits Q promise concurrency?
For instance, I have a method spawnProcess
. It returns a Q promise.
I want no more than 5 process spawned at a time, but transparently to the calling code.
What I need to implement is a function with signature
function limitConcurrency(promiseFactory, limit)
that I can call like
spawnProcess = limitConcurrency(spawnProcess, 5);
// use spawnProcess as usual
I already started working on my version, but I wonder if anyone has a concise implementation that I can check against.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…