stream method
Implementation
ActionStream<Chunk, Output> stream(
Input? input, {
Map<String, dynamic>? context,
Stream<Input>? inputStream,
Init? init,
}) {
final streamController = StreamController<Chunk>();
final actionStream = ActionStream<Chunk, Output>(streamController.stream);
run(
input,
context: context,
inputStream: inputStream,
init: init,
onChunk: (chunk) {
if (!streamController.isClosed) {
streamController.add(chunk);
}
},
)
.then((result) {
actionStream.setResult(result.result);
if (!streamController.isClosed) {
streamController.close();
}
})
.catchError((Object e, StackTrace s) {
actionStream.setError(e, s);
if (!streamController.isClosed) {
streamController.addError(e, s);
streamController.close();
}
});
return actionStream;
}