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

how do you handle errors here #6

Open
nichoth opened this issue Aug 20, 2016 · 2 comments
Open

how do you handle errors here #6

nichoth opened this issue Aug 20, 2016 · 2 comments

Comments

@nichoth
Copy link

nichoth commented Aug 20, 2016

function createMyStream (emitter) {
    var pushable = Pushable((err) => console.log('error', err))
    emitter.on('data', pushable.push.bind(pushable))
    emitter.on('end', pushable.end.bind(pushable))
    emitter.on('error', ???)
    return pushable
}

thanks

@dominictarr
Copy link
Member

pushable.end takes an argument, https://github.com/pull-stream/pull-pushable/blob/master/index.js#L28 that can be the error,

but really, it looks like you should use stream-to-pull-stream instead of pull-pushable

return toPull.source(emitter)

@nichoth
Copy link
Author

nichoth commented Aug 21, 2016

Ah ha. So pushable.end() can be the end event, and pushable.end(error) can be the error event. Thanks

function createMyStream (emitter) {
    var pushable = Pushable(function onEnd (err) {
        if (err) console.log(err)
        emitter.removeAllListeners()
    })
    emitter.on('data', (data) => pushable.push(data))
    emitter.on('end', () => pushable.end())
    emitter.on('error', (err) => pushable.end(err))
    return pushable
}

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

2 participants