on-one
v1.1.1
Published
Subscribe to one or more events and accept the first emitted
Maintainers
Readme
on-one
Subscribe to one or more events and accept the first emitted.
one event
import oo from 'on-one';
oo(stream, 'data', (chunk) => {
// first chunk only
})multiple events
import oo from 'on-one';
oo(stream, ['error', 'finish'], (err) => {
// first event to fire wins
})event name
The event name that triggered the callback is passed as the last argument:
import oo from 'on-one';
oo(stream, ['error', 'finish'], (err, eventName) => {
if (eventName === 'error') {
console.error('Stream failed:', err);
} else {
console.log('Stream finished successfully');
}
})