const Tag = Context.Tag<number>();
// the same applies to Effect.suspend
const tag = Layer.effect(
Tag,
Effect.gen(function* (_) {
yield* _(Effect.log("constructing..."));
const num = Math.random();
yield* _(Effect.log("layer constructed"));
return num
})
);
const prog = Effect.gen(function* (_) {
yield* _(Effect.log("starting..."));
// I assumed layer Tag will only get constructed when requested here or anywhere else. The layer still gets constructed even when not used i.e if I comment out the line below
const num = yield* _(Tag);
yield* _(Effect.log("running..." + num));
});
prog.pipe(Effect.provide(tag), Effect.runFork)
const Tag = Context.Tag<number>();
// the same applies to Effect.suspend
const tag = Layer.effect(
Tag,
Effect.gen(function* (_) {
yield* _(Effect.log("constructing..."));
const num = Math.random();
yield* _(Effect.log("layer constructed"));
return num
})
);
const prog = Effect.gen(function* (_) {
yield* _(Effect.log("starting..."));
// I assumed layer Tag will only get constructed when requested here or anywhere else. The layer still gets constructed even when not used i.e if I comment out the line below
const num = yield* _(Tag);
yield* _(Effect.log("running..." + num));
});
prog.pipe(Effect.provide(tag), Effect.runFork)