Skip to content

New "next" method that returns a promise that resolves when the event is emitted#24

Merged
pleek91 merged 3 commits intomainfrom
next-method
Feb 16, 2025
Merged

New "next" method that returns a promise that resolves when the event is emitted#24
pleek91 merged 3 commits intomainfrom
next-method

Conversation

@pleek91
Copy link
Copy Markdown
Collaborator

@pleek91 pleek91 commented Feb 16, 2025

Description

A common use case for event based systems is to pause execution of one task until a specific event is emitted. The once method has the functionality for getting the next event, but we can easily add a utility that turns that into a promise. Decided to call it "next" though I'm not tied to that name.

const payload = await emitter.next() // any event
const payload = await emitter.next('event-name') // specific event

There is also an optional timeout option that can be passed witch will automatically reject the promise after the timeout has expired if the expected event has not been emitted.

const payload = await emitter.next('event-name', { timeout: 100 })

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 16, 2025

Deploy Preview for kitbag-events ready!

Name Link
🔨 Latest commit c73ca14
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-events/deploys/67b133225905eb000876db34
😎 Deploy Preview https://deploy-preview-24--kitbag-events.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great feature. I would love it if the name reflected how similar it is to once, but I can't think of anything

@pleek91 pleek91 merged commit 638b4fb into main Feb 16, 2025
5 checks passed
@pleek91 pleek91 deleted the next-method branch February 17, 2025 01:42
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

Successfully merging this pull request may close these issues.

2 participants