Effect CommunityEC
Effect Community2y ago
6 replies
Aldwin

Synchronous Side Effects in Generators: Best Practices

Is it considered idiomatic/okay to put synchronous side effects right inside my generator?

Effect.gen(function*($){
  const result = yield* $(resultEffect);
  yield* $(Effect.sync(() => {
    myGlobalState = result;
  }));
  return result;
});

// ...vs...

Effect.gen(function*($){
  const result = yield* $(resultEffect);
  myGlobalState = result;
  return result;
});


I've been using the first of two approaches "just to be safe", but it can be pretty boilerplatey.
Was this page helpful?