-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling errors from child formulas (#364)
* Handling errors from child formulas * Add termination side effects * Poll transition queue on termination * Try finally block for isRunning * Add some tests * Add another test * Implement termination without executing local transition queue and docs update * Fix typo
- Loading branch information
Showing
8 changed files
with
297 additions
and
28 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
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
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
32 changes: 32 additions & 0 deletions
32
formula/src/test/java/com/instacart/formula/subjects/ChildErrorAfterToggleFormula.kt
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,32 @@ | ||
package com.instacart.formula.subjects | ||
|
||
import com.instacart.formula.Evaluation | ||
import com.instacart.formula.Formula | ||
import com.instacart.formula.Snapshot | ||
import com.instacart.formula.subjects.ChildErrorAfterToggleFormula.Output | ||
import com.instacart.formula.subjects.ChildErrorAfterToggleFormula.State | ||
|
||
class ChildErrorAfterToggleFormula: Formula<HasChildrenFormula.ChildParamsInput<()-> Unit>, State, Output>() { | ||
data class Output( | ||
val errorToggle: () -> Unit, | ||
val listener: () -> Unit | ||
) | ||
|
||
data class State(val throwError: Boolean = false) | ||
|
||
override fun initialState(input: HasChildrenFormula.ChildParamsInput<()-> Unit>) = State() | ||
|
||
override fun Snapshot<HasChildrenFormula.ChildParamsInput<()-> Unit>, State>.evaluate(): Evaluation<Output> { | ||
if (state.throwError) throw RuntimeException() | ||
return Evaluation( | ||
output = Output( | ||
errorToggle = context.callback() { | ||
transition(state.copy(throwError = !state.throwError)) | ||
}, | ||
listener = context.callback { | ||
transition { input.value() } | ||
} | ||
), | ||
) | ||
} | ||
} |
Oops, something went wrong.