Signals and considerations for parallel programming

I’m using the Signal library and finding it enjoyable to learn.

Right now, for my animation program design, it’s simplest to think of having global state that will need to be accessed by units in the Effect monad in several places. I’m thinking of using Effect.Ref to hold a mutable reference which I pass into other Effect computations that will all be passed to runSignal.

Can I safely assume that any given Effect computation I write to access this global will never be interrupted by other signals or Effect computations? In other words, it doesn’t have to worry about leaving the global state in a temporarily bad state as long as it fixes it before leaving the routine?


That sounds right – JavaScript is a single-threaded thing, so a function won’t be pre-empted while it’s running, which means you don’t have to worry about two functions touching the shared global state at the same time.

1 Like