-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate formula emit from evaluate. #340
Conversation
@@ -56,8 +59,15 @@ class FormulaRuntime<Input : Any, Output : Any>( | |||
* this [FormulaRuntime] instance. We will not accept any more [onInput] changes and will | |||
* not emit any new [Output] events. | |||
*/ | |||
@Volatile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that we see the latest value within emitOutputIfNeeded
private val inspector = FormulaPlugins.inspector(type = formula.type(), local = inspector) | ||
private val implementation = formula.implementation() | ||
|
||
@Volatile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that we see the latest value within emitOutputIfNeeded
@@ -44,6 +44,7 @@ internal class FormulaManagerImpl<Input, State, Output>( | |||
* start new actions. And then, [performTerminationSideEffects] is called to clean | |||
* up this [formula] and its child formulas. | |||
*/ | |||
@Volatile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that we see the latest value within emitOutputIfNeeded
@@ -13,7 +13,9 @@ import java.util.concurrent.atomic.AtomicReference | |||
* that there is happens-before relationship between each thread and memory changes are visible | |||
* between them. | |||
*/ | |||
class SynchronizedUpdateQueue { | |||
class SynchronizedUpdateQueue( | |||
val onEmpty: () -> Unit = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add optional onEmpty
so we can emit output only once all updates are processed.
JaCoCo Code Coverage 80.32% ✅
Generated by 🚫 Danger |
@@ -193,9 +203,6 @@ class FormulaRuntime<Input : Any, Output : Any>( | |||
if (isExecutingEffects) return | |||
executeTransitionEffects() | |||
|
|||
if (!manager.isTerminated()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be emitted once the update queue is empty
b5433ff
to
fb7d19d
Compare
fb7d19d
to
d9f6708
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What
Currently, formula evaluations will have to wait until output emission is finalized. If formula output emission triggers an expensive render, it will block further processing until emission is done and likely will force subsequent updates to the main thread. To avoid that, we are separating emission from formula run.