import { type Operation } from "https://deno.land/x/effection@4.0.0-alpha.1/lib/mod.ts";
An Operation
in Effection describes an abstract computation. An operation
does not do anything on its own. Rather, it only describes the steps it will
take when it runs.
In the Effection world, Operation
occupies the same position as Promise
does the world of async/await.
An operation can be created with a generator function that only does yield*
to other operations:
Examples
Example 1
Example 1
import { sleep } from "effection";
function* slow5(seconds) {
yield* sleep(seconds * 1000);
return 5;
}
Operations can also be created using Symbol.iterator
. The following
operation is the same as above:
Example 2
Example 2
import { sleep } from "effection";
const slow5 = (seconds) => ({
*[Symbol.iterator]() {
yield* sleep(seconds * 1000);
return 5;
}
})
See Operations guide for more information.