diff --git a/lib/call.ts b/lib/call.ts index fb9cfb89..5e85e4b1 100644 --- a/lib/call.ts +++ b/lib/call.ts @@ -32,22 +32,13 @@ export type Callable = | (() => T); /** - * Pause the current operation, then runs a promise, async function, plain function, - * or operation within a new scope. The calling operation will be resumed (or errored) + * Pause the current operation, then run an async function, or operation function in a new scope. The calling operation will be resumed (or errored) * once call is completed. * * `call()` is a uniform integration point for calling async functions, - * evaluating promises, generator functions, operations, and plain - * functions. + * and generator functions. * - * It can be used to treat a promise as an operation: - * - * @example - * ```javascript - * let response = yield* call(fetch('https://google.com')); - * ``` - * - * or an async function: + * It can be used to invoke an async function: * * @example * ```typescript @@ -70,13 +61,6 @@ export type Callable = * }); // => socket is destroyed before returning * ``` * - * It can be used to run a plain function: - * - * @example - * ```javascript - * yield* call(() => "a string"); - * ``` - * * Because `call()` runs within its own {@link Scope}, it can also be used to * establish [error boundaries](https://frontside.com/effection/docs/errors). * @@ -110,9 +94,31 @@ export type Callable = */ export function call(callable: () => Operation): Operation; export function call(callable: () => Promise): Operation; + +/** + * @deprecated Using call with simple functions will be removed in v4. + * To convert simple functions into operations, use @{link lift}. + */ export function call(callable: () => T): Operation; + +/** + * @deprecated calling bare promises, operations, and constants will + * be removed in v4, always pass a function to call() + * + * before: call(operation); + * after: call(() => operation); + */ export function call(callable: Operation): Operation; + +/** + * @deprecated calling bare promises, operations, and constants will + * be removed in v4, always pass a function to call() + * + * before: call(promise); + * after: call(() => promise); + */ export function call(callable: Promise): Operation; + export function call(callable: Callable): Operation { return action(function* (resolve, reject) { try { diff --git a/lib/types.ts b/lib/types.ts index be841d9f..f30b8681 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -244,7 +244,7 @@ export interface Subscription { * Unless a context value is defined for a particular scope, it will inherit * its value from its parent scope. */ -export interface Context extends Operation { +export interface Context { /** * A unique identifier for this context. */ @@ -265,6 +265,11 @@ export interface Context extends Operation { * set, and there is no default value, then this will return `undefined`. */ get(): Operation; + + /** + * @deprecated instead of using a bare context as an operation, use `Context.expect()` instead + */ + [Symbol.iterator]: Operation[typeof Symbol.iterator]; } /**