-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function _make(options) { | ||
var newOptions = {}; | ||
if (options.start) { | ||
newOptions.start = function(controller) { | ||
return options.start(controller)(); | ||
}; | ||
} | ||
if (options.write) { | ||
newOptions.write = function(chunk, controller) { | ||
return options.write(controller)(chunk)(); | ||
}; | ||
} | ||
if (options.close) { | ||
newOptions.close = function(controller) { | ||
return options.close(controller)(); | ||
}; | ||
} | ||
if (options.abort) { | ||
newOptions.abort = function(reason) { | ||
return options.abort(reason)(); | ||
}; | ||
} | ||
return newOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Web.Streams.Sink | ||
( Sink | ||
, Optional | ||
, make | ||
) where | ||
|
||
import Effect (Effect) | ||
import Effect.Exception (Error) | ||
import Prelude (Unit) | ||
import Prim.Row as Row | ||
import Web.Promise (Promise) | ||
import Web.Streams.WritableStreamController (WritableStreamController) | ||
|
||
type Optional chunk = | ||
( start :: WritableStreamController chunk -> Effect (Promise Unit) | ||
, write :: WritableStreamController chunk -> chunk -> Effect (Promise Unit) | ||
, close :: WritableStreamController chunk -> Effect (Promise Unit) | ||
, abort :: Error -> Effect (Promise Unit) | ||
) | ||
|
||
foreign import data Sink :: Type -> Type | ||
|
||
make :: forall r rx chunk. Row.Union r rx (Optional chunk) => { | r } -> Sink chunk | ||
make = _make | ||
|
||
foreign import _make :: forall r chunk. { | r } -> Sink chunk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export function _new(source, strategy) { | ||
return new WritableStream(source, strategy); | ||
} | ||
|
||
export function close(stream) { | ||
return function() { | ||
return stream.close(); | ||
}; | ||
} | ||
|
||
export function _abort(stream, reason) { | ||
return function() { | ||
return stream.abort(reason); | ||
}; | ||
} | ||
|
||
export function locked(stream) { | ||
return function() { | ||
return stream.locked; | ||
}; | ||
} | ||
|
||
export function getWriter(stream) { | ||
return function() { | ||
return stream.getWriter(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Web.Streams.WritableStream | ||
( WritableStream | ||
, new | ||
, abort | ||
, close | ||
, getWriter | ||
, locked | ||
) where | ||
|
||
import Data.Maybe (Maybe) | ||
import Data.Nullable (Nullable, toNullable) | ||
import Effect (Effect) | ||
import Effect.Exception (Error) | ||
import Effect.Uncurried (EffectFn2, runEffectFn2) | ||
import Prelude (Unit) | ||
import Web.Promise (Promise) | ||
import Web.Streams.QueuingStrategy (QueuingStrategy) | ||
import Web.Streams.Sink (Sink) | ||
import Web.Streams.Writer (Writer) | ||
|
||
foreign import data WritableStream :: Type -> Type | ||
|
||
foreign import _new :: forall chunk. EffectFn2 (Sink chunk) (Nullable (QueuingStrategy chunk)) (WritableStream chunk) | ||
|
||
new :: forall chunk. Sink chunk -> Maybe (QueuingStrategy chunk) -> Effect (WritableStream chunk) | ||
new source strategy = runEffectFn2 _new source (toNullable strategy) | ||
|
||
foreign import _abort :: forall chunk. EffectFn2 (WritableStream chunk) Error (Promise Unit) | ||
|
||
abort :: forall chunk. WritableStream chunk -> Error -> Effect (Promise Unit) | ||
abort = runEffectFn2 _abort | ||
|
||
foreign import close :: forall chunk. WritableStream chunk -> Effect (Promise Unit) | ||
|
||
foreign import getWriter :: forall chunk. WritableStream chunk -> Effect (Writer chunk) | ||
|
||
foreign import locked :: forall chunk. WritableStream chunk -> Effect Boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function error(error) { | ||
return function(controller) { | ||
return function() { | ||
return controller.error(error); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Web.Streams.WritableStreamController where | ||
|
||
import Effect (Effect) | ||
import Effect.Exception (Error) | ||
import Prelude (Unit) | ||
|
||
foreign import data WritableStreamController :: Type -> Type | ||
|
||
foreign import error :: forall chunk. WritableStreamController chunk -> Error -> Effect Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function _write(writer, chunk) { | ||
return function() { | ||
return writer.write(chunk); | ||
}; | ||
} | ||
|
||
export function ready(writer) { | ||
return function() { | ||
return writer.ready; | ||
}; | ||
} | ||
|
||
export function close(writer) { | ||
return function() { | ||
return writer.close(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Web.Streams.Writer | ||
( Writer | ||
, write | ||
) where | ||
|
||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn2, runEffectFn2) | ||
import Prelude (Unit) | ||
import Web.Promise (Promise) | ||
|
||
foreign import data Writer :: Type -> Type | ||
|
||
foreign import _write :: forall chunk. EffectFn2 (Writer chunk) chunk (Promise Unit) | ||
|
||
write :: forall chunk. Writer chunk -> chunk -> Effect (Promise Unit) | ||
write = runEffectFn2 _write | ||
|
||
foreign import ready :: forall chunk. Writer chunk -> Effect (Promise Unit) | ||
|
||
foreign import close :: forall chunk. Writer chunk -> Effect (Promise Unit) |