A strategy for running an input loop asynchronously via Promise
.
- A
Input type.
- Z
Output type.
- E
Error type.
- LoopStrategyAsync
- getInput(): Promise<LoopAction<A, Z, E>>
Gets new input from somewhere e.g. reading a line.
Returns: Promise<LoopAction<A, Z, E>>
A loop action that can: step with the input; finish with some parsed value; fail due to an error.
- parse(input: A): Promise<LoopAction<null, Z, E>>
Parses given input into the desired type.
Parameters:
Name | Type | Description |
---|---|---|
input | A | The input. |
Returns: Promise<LoopAction<null, Z, E>>
A loop action that can: step on; finish with some parsed value; fail due to an error.
- onInputError(error: E): Promise<LoopAction<null, Z, E>>
Handles error on getting new input.
This function intercepts the fail
case of getInput
.
Parameters:
Name | Type | Description |
---|---|---|
error | E | The error encountered. |
Returns: Promise<LoopAction<null, Z, E>>
A loop action that can: step on; finish with some parsed value; fail due to an error.
- onParseError(error: E, input: A): Promise<LoopAction<null, Z, E>>
Handles error on parsing input.
This function intercepts the fail
case of parse
.
Parameters:
Name | Type | Description |
---|---|---|
error | E | The error encountered. |
input | A | The input that could not be parsed. |
Returns: Promise<LoopAction<null, Z, E>>
A loop action that can: step on; finish with some parsed value; fail due to an error.