Effect.sync: when does the code run?
Use Effect.sync to wrap synchronous code (including side effects) in an Effect. The code inside Effect.sync does not run when you call it—it runs only when you execute the Effect.
Watch the log order: you'll see "1" and "3" first; "2" appears only after you run the Effect.
- Use
Effect.sync(() => { ... })to wrap synchronous code in an Effect - The code inside
Effect.syncdoesn't execute until you run the Effect - Try running the Effect with
Effect.runSync(effect)to see all three logs
Loading code editor...