on-one
Version:
Subscribe to one or more events and accept the first emitted
38 lines (28 loc) • 637 B
Markdown
Subscribe to one or more events and accept the first emitted.
```js
import oo from 'on-one';
oo(stream, 'data', (chunk) => {
// first chunk only
})
```
```js
import oo from 'on-one';
oo(stream, ['error', 'finish'], (err) => {
// first event to fire wins
})
```
The event name that triggered the callback is passed as the last argument:
```js
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');
}
})
```