TL;DR

非同期処理を呼び出した結果を Effect でラップする関数。処理が reject しないと確信できるときに使う。

仕組み

Effect.promise は Promise を返す関数を受け取り、その結果を Effect にする。失敗しないと仮定するので、エラーの型(第 2 型パラメータ)は never になる。それでも Promise が reject した場合、そのエラーは型付きのエラーではなく、想定外のクラッシュ(defect)として扱われる。失敗する可能性があるなら Effect.tryPromise を使う。同期処理をラップするには Effect.sync を使う。

Promise は作った時点で処理が始まる(正格評価)が、Effect は実行するまで何もしない(遅延評価)。

例

const fetchRequest = Effect.promise(() => fetch("https://pokeapi.co/api/v2/pokemon/garchomp"))
// ^ Effect.Effect<Response, never, never>
 
const jsonResponse = (response: Response) => Effect.promise(() => response.json())
// ^ const jsonResponse: (response: Response) => Effect.Effect<any, never, never>

関連

出典