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

Automatic object stream piping #26

Open
mcollina opened this issue Sep 12, 2014 · 5 comments
Open

Automatic object stream piping #26

mcollina opened this issue Sep 12, 2014 · 5 comments

Comments

@mcollina
Copy link
Contributor

Currently, we cannot pass a standard objectMode stream inside a channel with automated piping: we need to create a new channel and pipe.

Is it sound to use that pattern? Plus, solving this issue might be more tricky, because Transform stream are not supported by the automated piping natively, you will need to flag them with something like jschanReadable or jschanWritable.

Any opinions on this?

@davidmarkclements
Copy link

Hey @mcollina can you elaborate with some (pseudo) code?

@mcollina
Copy link
Contributor Author

So you might want to use a https://www.npmjs.org/package/from2 fro generating some events to pop to a client.

Right now you have to do:

session.on('channel', function(chan) {
  chan.on('data', function(msg) {
    var chan = chan.WriteChannel()
    from2(...).pipe(chan)
    msg.returnChannel.end({
      more: chan,
      error: false
    })
  })
})

Using graft syntax:

through.obj(function(msg, enc, done) {
    var chan = msg._channel.WriteChannel()
    from2(...).pipe(chan)
    msg.returnChannel.end({
      more: chan,
      error: false
    })
})

However, with this you might want to use:

through.obj(function(msg, enc, done) {
    msg.returnChannel.end({
      more: from2(...),
      error: false
    })
})

and it gets automatically piped.

This would also greatly help seneca integration, as at that point it could just forget about channels.

The only point will be Transform streams, which must get an isReadChannel or isWriteChannel property hooked up.

@davidmarkclements
Copy link

could we abstract the pain by doing the channel switching under the hood in response to a pipe event?

@AdrianRossouw
Copy link
Contributor

deja vu? #22

@mcollina
Copy link
Contributor Author

@AdrianRossouw this is the missing bit for #22. However it requires some changes to msgpack5.

@davidmarkclements for sure! This requires some changes to msgpack5, if you want to help we can discuss the details there.

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

3 participants