We're using p-queue
within our Sanity Studio dashboard to run some batched actions. When setting this up all events run except for completed
. Which is really a head scratcher. I've created a reduced case in Replit and it works there, great! However, in my current setup all other methods seem to work except for complete
so trying to debug a bit futher.
My code setup below:
const stripeQueue = new PQueue({
concurrency: 2,
})
stripeQueue.on('completed', result => {
console.log('completd: ', result);
});
stripeQueue.on('idle', (data) => {
console.log('queue id idle: ', data);
});
stripeQueue.on('next', () => {
console.log(`Next:: Task is completed. Size: ${stripeQueue.size} Pending: ${stripeQueue.pending}`);
});
stripeQueue.on('error', (error) => {
console.log(`Error:: `, error);
});
const addItemsToQueue = () => {
console.log('before stripeQueue add')
stripeQueue.add(() => Promise.resolve('hello, world 1!'));
console.log('after 1')
stripeQueue.add(() => Promise.resolve('hello, world 2!'));
console.log('after 2')
}
function TestComponent () {
return(
<div
header="Members"
>
<button onClick={() => addItemsToQueue()}>Click me</button>
</div>
)
}
What's crazy, even in that small test case in my environment this is the result:
before stripeQueue add
index.js:151 after 1
index.js:153 after 2
index.js:133 Next:: Task is completed. Size: 2 Pending: 2
index.js:133 Next:: Task is completed. Size: 1 Pending: 2
index.js:133 Next:: Task is completed. Size: 0 Pending: 2
index.js:133 Next:: Task is completed. Size: 0 Pending: 1
index.js:129 queue id idle: undefined
index.js:133 Next:: Task is completed. Size: 0 Pending: 0
I do realize you request a MVP use case. I'm happy to attempt to make one past the basic Replit however it may be challenging given the use case is within a CMS that is using React on the front-end and sending data back to the server.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too