Effect CommunityEC
Effect Community9mo ago
8 replies
gavriguy

nested runPromise

I'm using a third party library that imports ServerSentEventGenerator(https://github.com/starfederation/datastar/tree/main/sdk/typescript)

I create the following fuction to be able to pass it an Effect factory:

export const runStream = <A, E>(
  makeEffect: (stream: ServerSentEventGenerator) => Effect.Effect<
    A,
    E,
    ManagedRuntime.ManagedRuntime.Context<typeof runtime> | HonoContext
  >,
) =>
async (c: Context) => {
  const exit = await runtime.runPromiseExit(
    Effect.tryPromise(async () =>
      ServerSentEventGenerator.stream(async (stream) => {
        await runtime.runPromise(
          makeEffect(stream).pipe(
            HonoContext.provide(c),
            Effect.withSpan(c.req.url),
          ),
        );
      })
    ),
  );
  if (Exit.isSuccess(exit)) {
    return exit.value;
  } else {
    const error = Cause.squash(exit.cause);
    console.error(Cause.pretty(exit.cause));
    throw new Error("internal server error");
  }
};


The issue is that I have a runPromise inside a runPromiseExit. Can I somehow lift (I'm not sure lift the right verb) the inner runPromise to a regular Effect?
GitHub
The hypermedia framework. Contribute to starfederation/datastar development by creating an account on GitHub.
datastar/sdk/typescript at main · starfederation/datastar
Was this page helpful?