import { Console, Effect, Ref, Stream, SubscriptionRef } from "effect";
const effect = Effect.gen(function* () {
const counter = yield* SubscriptionRef.make<number>(0);
const tickStream = counter.changes.pipe(
Stream.flatMap(
(count) => {
return Stream.tick("300 millis").pipe(Stream.map(() => count.toString()));
},
{
switch: true,
concurrency: "unbounded",
}
)
);
yield* Effect.forkDaemon(
Stream.runForEach(tickStream, (value) => Console.log("tick", value))
);
yield* Effect.sleep(100);
yield* Ref.set(counter, 1);
yield* Effect.sleep(100);
yield* Ref.set(counter, 2);
yield* Effect.sleep(1000000);
});
Effect.runPromise(effect);
import { Console, Effect, Ref, Stream, SubscriptionRef } from "effect";
const effect = Effect.gen(function* () {
const counter = yield* SubscriptionRef.make<number>(0);
const tickStream = counter.changes.pipe(
Stream.flatMap(
(count) => {
return Stream.tick("300 millis").pipe(Stream.map(() => count.toString()));
},
{
switch: true,
concurrency: "unbounded",
}
)
);
yield* Effect.forkDaemon(
Stream.runForEach(tickStream, (value) => Console.log("tick", value))
);
yield* Effect.sleep(100);
yield* Ref.set(counter, 1);
yield* Effect.sleep(100);
yield* Ref.set(counter, 2);
yield* Effect.sleep(1000000);
});
Effect.runPromise(effect);