How to Get the Response of an API Call Using Effect in TypeScript

hello everyone ,how i can get the response of executing an api with effect , always returns Promise { <pending> }
// todoApi
export class TodoApi2 extends Effect.Service<TodoApi2>()("TodoApi2", {
  effect: Effect.gen(function* () {
    const todosCollection = yield* TodosCollection;
    const buildTodoApiUrl = yield* BuildTodoApiUrl;

    return {
      getTodo: Effect.gen(function* () {
        const requestUrl = buildTodoApiUrl({
          id: todosCollection[0]
        });
        const response = yield* Effect.tryPromise({
          try: () => fetch(requestUrl),
          catch: (error: any) => new FetchError({ message: error.message })
        });

        if (!response.ok) {
          return yield* new FetchError({ message: response.statusText });
        }

        const json =
          yield *
          Effect.tryPromise({
            try: () => response.json(),
            catch: (error: any) => new JsonError({ message: error.message })
          });

        return yield* Schema.decodeUnknown(Todo)(json);
      })
    };
  }),
  dependencies: [TodosCollection.Default, BuildTodoApiUrl.Default]
}) {}

// program
const program = Effect.gen(function* () {
  const todoApi = yield* TodoApi2;
  return yield* todoApi.getTodo;
});


const MainLayer = Layer.mergeAll(TodoApi2.Default);
const TodoRuntime = ManagedRuntime.make(MainLayer);

// result
const res = TodoRuntime.runPromiseExit(program);

console.log(res);
Was this page helpful?