# call

```ts
function call<T>(callable: () => Operation<T>): Operation<T>
```

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,
and generator functions.

It can be used to invoke an async function:

### Examples
#### Example 1
```typescript
async function* googleSlowly() {
  return yield* call(async function() {
    await new Promise(resolve => setTimeout(resolve, 2000));
    return await fetch("https://google.com");
  });
}
```

It can be used to run an operation in a separate scope to ensure that any
resources allocated will be cleaned up:

---
#### Example 2
```javascript
yield* call(function*() {
  let socket = yield* useSocket();
  return yield* socket.read();
}); // => socket is destroyed before returning
```

Because `call()` runs within its own [Scope](https://frontside.com/effection/api/v3/Scope.md), it can also be used to
establish [error boundaries](https://frontside.com/effection/docs/errors).

---
#### Example 3
```javascript
function* myop() {
  let task = yield* spawn(function*() {
    throw new Error("boom!");
  });
  yield* task;
}

function* runner() {
  try {
    yield* myop();
  } catch (err) {
    // this will never get hit!
  }
}

function* runner() {
  try {
    yield* call(myop);
  } catch(err) {
    // properly catches `spawn` errors!
  }
}
```

---
### Type Parameters
T


### Parameters


**callable**: () => [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;


the operation, promise, async function, generator funnction, or plain function to call as part of this operation
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L95)

```ts
function call<T>(callable: () => Promise<T>): Operation<T>
```

### Type Parameters
T


### Parameters


**callable**: () => Promise&lt;T&gt;
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L96)

```ts
function call<T>(callable: () => T): Operation<T>
```

<div class="border-l-4 border-red-500 mt-1 [&>*]:my-0 pl-3">
          <span class="text-red-500 font-bold">Deprecated</span>

          Using call with simple functions will be removed in v4.
To convert simple functions into operations, use [lift](https://frontside.com/effection/api/v3/lift.md).
          
        </div>
        
### Type Parameters
T


### Parameters


**callable**: () => T
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L102)

```ts
function call<T>(callable: Operation<T>): Operation<T>
```

<div class="border-l-4 border-red-500 mt-1 [&>*]:my-0 pl-3">
          <span class="text-red-500 font-bold">Deprecated</span>

          calling bare promises, operations, and constants will
be removed in v4 use [until](https://frontside.com/effection/api/v3/until.md) instead

before: call(operation);
after:  until(operation);
          
        </div>
        
### Type Parameters
T


### Parameters


**callable**: [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L111)

```ts
function call<T>(callable: Promise<T>): Operation<T>
```

<div class="border-l-4 border-red-500 mt-1 [&>*]:my-0 pl-3">
          <span class="text-red-500 font-bold">Deprecated</span>

          calling bare promises, operations, and constants will
be removed in v4, always pass a function to call()

before: call(promise);
after:  call(() => promise);
          
        </div>
        
### Type Parameters
T


### Parameters


**callable**: Promise&lt;T&gt;
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L120)

```ts
function call<T>(callable: Callable<T>): Operation<T>
```

### Type Parameters
T


### Parameters


**callable**: [Callable](https://frontside.com/effection/api/v3/Callable.md)&lt;T&gt;
### Return Type


[Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/call.ts#L122)
