From a347c05062f57baba23a7a9c9c6c24856298cbab Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 13 May 2024 21:17:28 -0500 Subject: [PATCH] wip: explore removing delays(3) --- src/Node.Stream.Object.js | 3 +++ src/Node.Stream.Object.purs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/Node.Stream.Object.js b/src/Node.Stream.Object.js index 2bdaaa7..f3af9fc 100644 --- a/src/Node.Stream.Object.js +++ b/src/Node.Stream.Object.js @@ -12,6 +12,9 @@ export const isClosedImpl = (s) => () => s.closed; /** @type {(s: Stream.Writable | Stream.Transform) => () => boolean} */ export const isWritableImpl = (s) => () => s.writable; +/** @type {(s: Stream.Writable | Stream.Transform) => () => boolean} */ +export const needsDrainImpl = (s) => () => s.writableNeedDrain; + /** @type {(s: Stream.Readable | Stream.Transform) => () => boolean} */ export const isReadableEndedImpl = (s) => () => s.readableEnded; diff --git a/src/Node.Stream.Object.purs b/src/Node.Stream.Object.purs index 27c566c..c7bffce 100644 --- a/src/Node.Stream.Object.purs +++ b/src/Node.Stream.Object.purs @@ -60,6 +60,7 @@ foreign import isWritableImpl :: forall s. s -> Effect Boolean foreign import isReadableEndedImpl :: forall s. s -> Effect Boolean foreign import isWritableEndedImpl :: forall s. s -> Effect Boolean foreign import isClosedImpl :: forall s. s -> Effect Boolean +foreign import needsDrainImpl :: forall s. s -> Effect Boolean foreign import readableLengthImpl :: forall s. s -> Effect Int readResultFFI :: forall a. ReadResultFFI a @@ -89,6 +90,7 @@ class Stream s <= Read s a | s -> a where class Stream s <= Write s a | s -> a where isWritable :: s -> Effect Boolean + needsDrain :: s -> Effect Boolean isWritableEnded :: s -> Effect Boolean write :: s -> a -> Effect WriteResult end :: s -> Effect Unit @@ -114,16 +116,19 @@ instance Write (Writable a) a where isWritableEnded = isWritableEndedImpl write s = writeImpl writeResultFFI s end = endImpl + needsDrain = needsDrainImpl else instance Write (Transform a b) a where isWritable = isWritableImpl isWritableEnded = isWritableEndedImpl write s = writeImpl writeResultFFI s end = endImpl + needsDrain = needsDrainImpl else instance (Write s a) => Write s a where isWritable = isWritableImpl isWritableEnded = isWritableEndedImpl write s a = write s a end s = end s + needsDrain = needsDrainImpl withErrorST :: forall s. Stream s => s -> Effect { cancel :: Effect Unit, error :: STRef Global (Maybe Error) } withErrorST s = do