Effect CommunityEC
Effect Community3y ago
6 replies
Max Khramtsov

Effective Way to Write Code for Handling Bot Events

What is effect-way to write this piece of code? I'm stuck (
    const launch =
      (bot: TelegrafBot._Bot) =>
      <E, A>(handleBotEvents: Effect.Effect<never, E, A>) => {
        const run: Effect.Effect<never, TelegrafLaunchError, void> = pipe(
          Effect.runPromiseExit(handleBotEvents), // handling of infinite streams of bot's events
          () =>
            Effect.tryPromise({
              try: () => {
                console.log("launching");
                return bot.launch(); // run builded bot
              },
              catch: (cause) => new TelegrafLaunchError({ cause }),
            }),
          Effect.orElse(() => run), // relounch bot
        );

        return run;
      };
Was this page helpful?