class NotificationsEffect extends Effect.Tag("NotificationsEffect")<
NotificationsEffect,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
class NotificationsContext extends Context.Tag("NotificationsContext")<
NotificationsContext,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
async function main() {
const runtime = ManagedRuntime.make(
Layer.mergeAll(NotificationsEffect.Live, NotificationsContext.Live)
);
await runtime.runPromise(NotificationsEffect.notify("Hello, world!"));
await runtime.runPromise(
Effect.gen(function* () {
const notificationsContext = yield* NotificationsContext;
yield* notificationsContext.notify("Hello, world!");
})
);
await runtime.dispose();
}
main().then(() => console.log("Program completed successfully."));
class NotificationsEffect extends Effect.Tag("NotificationsEffect")<
NotificationsEffect,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
class NotificationsContext extends Context.Tag("NotificationsContext")<
NotificationsContext,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
async function main() {
const runtime = ManagedRuntime.make(
Layer.mergeAll(NotificationsEffect.Live, NotificationsContext.Live)
);
await runtime.runPromise(NotificationsEffect.notify("Hello, world!"));
await runtime.runPromise(
Effect.gen(function* () {
const notificationsContext = yield* NotificationsContext;
yield* notificationsContext.notify("Hello, world!");
})
);
await runtime.dispose();
}
main().then(() => console.log("Program completed successfully."));