You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nodes are asynchronous by default. It means they can receive next messages before previous are processed. Sometimes this lead to race conditions, especially when working with side-effects (see #857 for more details).
Because of that, we need to manually introduce locks, which is boilerplate and makes code harder to reason about. For example, For component does that. However, we going to need this kind of logic more and, which is most important, we need to empower user to synchronize nodes easily when needed.
Solution
At the moment sync package only contains one component WaitGroup. We need generic component Sync that will turn async node into a sync one. Here "sync" means "will not receive next message before previous one is fully processed".
Add code
Add e2e test (e.g. print stream of numbers using sync.Sync instead of For asserting specific order)
import { state }
// Sync prevents node from receiving next message before previous one is processed.
def Sync<T, Y>(data T) (res Y, err error) {
is_first state.Bool
lock Lock<T>
handler ISyncHandler<T, Y>?
---
false -> is_first:init
:data -> [lock:data, is_first:get]
[is_first:then, handler] -> lock:sig
lock -> handler -> :res
}
// ISyncHandler defines async node that needs to be synchronized.
pub interface ISyncHandler<T, Y>(T) (res Y, err error)
The text was updated successfully, but these errors were encountered:
WARNING: Depends on #862
Problem
Nodes are asynchronous by default. It means they can receive next messages before previous are processed. Sometimes this lead to race conditions, especially when working with side-effects (see #857 for more details).
Because of that, we need to manually introduce locks, which is boilerplate and makes code harder to reason about. For example,
For
component does that. However, we going to need this kind of logic more and, which is most important, we need to empower user to synchronize nodes easily when needed.Solution
At the moment
sync
package only contains one componentWaitGroup
. We need generic componentSync
that will turn async node into a sync one. Here "sync" means "will not receive next message before previous one is fully processed".sync.Sync
instead ofFor
asserting specific order)The text was updated successfully, but these errors were encountered: