import {Console, Effect, Schedule, Scope, Stream} from "effect";
import {NodeRuntime} from "@effect/platform-node";
const intervalStream = Stream.fromSchedule(Schedule.spaced('1 second'))
.pipe(Stream.broadcastDynamic(999))
const program = Effect.gen(function *(){
const scope = yield* Scope.make()
const stream = yield * intervalStream.pipe(Scope.extend(scope) );
const backgroundTask = yield * stream.pipe(
Stream.take(5),
Stream.schedule(Schedule.spaced("10 second")),
Stream.tap(x=>Console.log(`daemon`, x)),
Stream.ensuring(Console.log(`Daemon killed`)),
Stream.runDrain,
Effect.uninterruptible,
Effect.forkDaemon
);
return yield * stream.pipe(Stream.take(3),Stream.tap((x) => Console.log('main', x)), Stream.runCount);
})
NodeRuntime.runMain((program))
import {Console, Effect, Schedule, Scope, Stream} from "effect";
import {NodeRuntime} from "@effect/platform-node";
const intervalStream = Stream.fromSchedule(Schedule.spaced('1 second'))
.pipe(Stream.broadcastDynamic(999))
const program = Effect.gen(function *(){
const scope = yield* Scope.make()
const stream = yield * intervalStream.pipe(Scope.extend(scope) );
const backgroundTask = yield * stream.pipe(
Stream.take(5),
Stream.schedule(Schedule.spaced("10 second")),
Stream.tap(x=>Console.log(`daemon`, x)),
Stream.ensuring(Console.log(`Daemon killed`)),
Stream.runDrain,
Effect.uninterruptible,
Effect.forkDaemon
);
return yield * stream.pipe(Stream.take(3),Stream.tap((x) => Console.log('main', x)), Stream.runCount);
})
NodeRuntime.runMain((program))