Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing complete event when its the only non-respondent event. #169

Open
patrickbjohnson opened this issue Oct 11, 2022 · 1 comment
Open

Comments

@patrickbjohnson
Copy link

Current Stack

  1. Vercel
  2. Nuxt
  3. Sanity

Context

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.

@patrickbjohnson
Copy link
Author

This turned out to be a "personal problem". This code does not work in the browser but does in node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant