-
Notifications
You must be signed in to change notification settings - Fork 601
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
Improve Node.js Readable
/Writable
converters, introduce Duplex
converter
#2496
Conversation
@@ -134,7 +137,12 @@ private[fs2] trait ioplatform { | |||
}.drain | |||
} | |||
|
|||
def mkWritable[F[_]](implicit F: Async[F]): Resource[F, (Writable, Stream[F, Byte])] = | |||
def mkWritable[F[_]: Async](f: Writable => F[Unit]): Stream[F, Byte] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the name of this method, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readWritable
? Not my favorite but matches the convention used on JVM side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan myself, but I do like the consistency. Also renamed from{Readable,Writable}
to readReadable
and writeWritable
.
if (!readable.readableEnded) | ||
if (!readable.readableEnded & destroyIfNotEnded) | ||
F.delay(readable.destroy()) | ||
else | ||
F.unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not thrilled with this but I think it is the best we can do. The underlying issue is that Node.js has no way to close/"end" a Readable
besides the nuclear option destroy
. This same thing came up in #2453 (comment) when we couldn't implement the endOfInput
method for sockets.
Readable
/Writable
converters more idiomaticReadable
/Writable
converters
Readable
/Writable
convertersReadable
/Writable
converters, introduce Duplex
converter
def readWritable[F[_]: Async](f: Writable => F[Unit]): Stream[F, Byte] = | ||
Stream.empty.through(toDuplexAndRead(f)) | ||
|
||
def toDuplexAndRead[F[_]: Async](f: Duplex => F[Unit]): Pipe[F, Byte, Byte] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An even funkier name! Thoughts? 😅
@mpilquist apologies for all the churn. In these latest commits I introduced the
Thanks! |
Closing in favor of #2504 because it's easier to debug these converters alongside the socket implementations. |
Idiomatic APIs as inspired by their JVM cousins.
Edit: this PR is becoming a catch-all for other fixes.
Edit 2: okay, I ended up doing some major reworking in anticipation of new socket implementations.