diff --git a/docs/task-instance.md b/docs/task-instance.md index 7e2233b1..10aa8683 100644 --- a/docs/task-instance.md +++ b/docs/task-instance.md @@ -140,7 +140,9 @@ const task: Task = Task.of(5).chain(number => {% tab title="Type Definition" %} ```typescript -type chain = (fn: (result: S) => Task | Promise) => Task +type chain = ( + fn: (result: S) => Task | Promise +) => Task ``` {% endtab %} diff --git a/src/Task/Task.ts b/src/Task/Task.ts index 32f69116..2f4a5896 100644 --- a/src/Task/Task.ts +++ b/src/Task/Task.ts @@ -103,10 +103,10 @@ export const fork = ( * @param fn Takes a successful result and returns a new task. * @param task The task which will chain to the next one on success. */ -export const chain = ( - fn: (result: S) => Task | Promise, +export const chain = ( + fn: (result: S) => Task | Promise, task: Task -): Task => +): Task => new Task((reject, resolve) => task.fork(reject, b => autoPromiseToTask(fn(b)).fork(reject, resolve)) )