Effect CommunityEC
Effect Community3y ago
1 reply
Sadra

Adding File Functions to Context in TypeScript

is my way right for adding whole other file functoins type into effect context ?
import * as deps from "./dep";
type Deps = typeof deps;
export type CTX = Deps & {};
export const ctx = Context.Tag<CTX>();
const context = Context.empty().pipe(Context.add(ctx, ctx.of({ ...deps })));

const program = ctx.pipe(
  Effect.flatMap((ctx) =>
    Effect.sync(() => ctx.showTime()).pipe(
      Effect.tap(() => Effect.sleep(1000)),
      Effect.tap(() => Effect.sync(() => ctx.showTime()))
    )
  )
);

const runnable = Effect.provide(program, context);
Effect.runPromise(runnable);
Was this page helpful?