You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node: cursors should be readable object streams #3600
right now the docs say they inherit from event emitter. a readable object stream should be returned instead, which would be backwards compatible but would also properly buffer as well as .pipe().
@jonathanong Would it be reasonable to just provide the .pipe method instead? In terms of "proper" buffering, what are you looking for specifically that the current driver doesn't provide?
Sorry! I wasn't expressing myself very well. My question is about whether it's enough to implement streams in a duck-typed manner (which we currently provide all the same methods except for .pipe and .then) or whether we should actually subclass ReadableStream, because it's common to do typeof comparisons.
I'm trying to understand the issue a bit better than I currently do. Thanks for taking the time to bring this issue up
because you're going to introduce bugs? i don't see this as "benefits". i see "costs" of not doing it. it's also easier to properly implement readable streams.
Node.js streams are basically an attempt to provide a standard interface for streams, but it is still tagged as unstable even with Node 0.12 -- https://nodejs.org/api/stream.html#stream_stream
One interesting thing with providing a Node.js stream is that because it is a standard, you can pipe it to a Transform streams or a Writable streams - that other libraries can implement, like the fs module, process.stdout etc..
One important caveat with streams is that it was implemented for buffers. You can set it to ouput objects/values, but in this case, null is a forbidden value (sending null means that the stream has ended).
So, given the null problem, I think we should probably do like RethinkDBdash and provide a .toStream method. Then the user can decide if nulls are a risk
@deontologician you're talking about implementing .toStream() on queries, not the cursor object right?
It's also worth noting that currently rethinkdbdash simply drops null values from the stream but as @neumino mentioned there are other options. I would lean towards emitting undefined in place of null but keep in mind that's only supported as of v0.12.0.
Queries can't support toStream since they have to be executed by the server. Either the cursor or the run method would have to have an option to turn a cursor into a stream.
I think @marshall007 was asking because rethinkdbdash seems to have the toStream() method directly on the query.
That only works because it has a connection pool though, so the run is implicit in that case.
Activity
danielmewes commentedon Jan 19, 2015
Pinging @deontologician
(can't really comment myself since I don't know much JS)
deontologician commentedon Jan 23, 2015
I'm not up to date on this stuff, I'd need to read the docs related to it
deontologician commentedon Feb 10, 2015
@jonathanong Would it be reasonable to just provide the
.pipemethod instead? In terms of "proper" buffering, what are you looking for specifically that the current driver doesn't provide?jonathanong commentedon Feb 10, 2015
yes, but don't implement your own. use
require('stream').Readable's pipe implementation.deontologician commentedon Feb 10, 2015
I guess I'm asking what the benefit is to reimplementing it as a readable stream, vs. just adding a pipe method to our existing implementation.
jonathanong commentedon Feb 10, 2015
i'm not sure how to answer that. the way i read this is, "what is the benefit of being standards compliant?".
deontologician commentedon Feb 10, 2015
Sorry! I wasn't expressing myself very well. My question is about whether it's enough to implement streams in a duck-typed manner (which we currently provide all the same methods except for
.pipeand.then) or whether we should actually subclass ReadableStream, because it's common to dotypeofcomparisons.I'm trying to understand the issue a bit better than I currently do. Thanks for taking the time to bring this issue up
jonathanong commentedon Feb 10, 2015
because you're going to introduce bugs? i don't see this as "benefits". i see "costs" of not doing it. it's also easier to properly implement readable streams.
maybe you're asking if you can just do:
which is fine, but it should be a readable stream's
pipe()deontologician commentedon Feb 10, 2015
Ok cool, thanks for clarifying. I think we'll do this, I just wanted to make sure I understood the reasoning behind it
coffeemug commentedon Feb 10, 2015
Ping @neumino. Would you mind giving a bit of feedback on this, since you understand the ecosystem really well?
neumino commentedon Feb 10, 2015
Node.js streams are basically an attempt to provide a standard interface for streams, but it is still tagged as unstable even with Node 0.12 -- https://nodejs.org/api/stream.html#stream_stream
One interesting thing with providing a Node.js stream is that because it is a standard, you can pipe it to a Transform streams or a Writable streams - that other libraries can implement, like the
fsmodule,process.stdoutetc..One important caveat with streams is that it was implemented for buffers. You can set it to ouput objects/values, but in this case,
nullis a forbidden value (sendingnullmeans that the stream has ended).So while it's nice to have, it cannot completely replace the current interface with cursors (except if you pass
nullvalues as a ReQL pseudo type orundefinedin the streams).It's also relatively little work to add a Stream interface. I did it in rethinkdbdash, and it's about 150 lines -- https://github.com/neumino/rethinkdbdash/blob/master/lib/stream.js.
Note: In rethinkdbdash, streams are currently implemented with the current API:
The stream is not returned by the promise of
runbecause it would require to cache errors in multiple places:danielmewes commentedon Feb 10, 2015
Thanks for the info @neumino !
internalfx commentedon Feb 10, 2015
I like the idea of using streams. 👍
deontologician commentedon Feb 10, 2015
So, given the
nullproblem, I think we should probably do like RethinkDBdash and provide a.toStreammethod. Then the user can decide if nulls are a riskmarshall007 commentedon Feb 13, 2015
@deontologician you're talking about implementing
.toStream()on queries, not thecursorobject right?It's also worth noting that currently
rethinkdbdashsimply dropsnullvalues from the stream but as @neumino mentioned there are other options. I would lean towards emittingundefinedin place ofnullbut keep in mind that's only supported as of v0.12.0.deontologician commentedon Feb 13, 2015
Queries can't support toStream since they have to be executed by the server. Either the cursor or the run method would have to have an option to turn a cursor into a stream.
danielmewes commentedon Feb 13, 2015
I think @marshall007 was asking because rethinkdbdash seems to have the
toStream()method directly on the query.That only works because it has a connection pool though, so the
runis implicit in that case.