# action

```ts
function action<T>(enter: (resolve: Resolve<T>, reject: Reject) => () => void): Operation<T>
```

Create an [Operation](https://frontside.com/effection/api/v3/Operation.md) that can be either resolved (or rejected) with
a synchronous callback. This is the Effection equivalent of `new Promise()`.

The action body is a function that enters the effect, and returns a function that
will be called to exit the action..

For example:

```js
let five = yield* action((resolve, reject) => {
  let timeout = setTimeout(() => {
    if (Math.random() > 5) {
      resolve(5)
    } else {
      reject(new Error("bad luck!"));
    }
  }, 1000);
  return () => clearTimeout(timeout);
});
```

### Type Parameters
T
type of the action's result.


### Parameters


**enter**: (**resolve**: [Resolve](https://frontside.com/effection/api/v3/Resolve.md)&lt;T&gt;, **reject**: [Reject](https://frontside.com/effection/api/v3/Reject.md)) => () => void


enter and exit the action
### Return Type


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


an operation producing the resolved value, or throwing the rejected error

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

```ts
function action<T>(operation: (resolve: Resolve<T>, reject: Reject) => Operation<void>): 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>

          `action()` used with an operation will be removed in v4.
          
        </div>
        
### Type Parameters
T


### Parameters


**operation**: (**resolve**: [Resolve](https://frontside.com/effection/api/v3/Resolve.md)&lt;T&gt;, **reject**: [Reject](https://frontside.com/effection/api/v3/Reject.md)) => [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;void&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/instructions.ts#L86)

```ts
function action<T>(operation: ((resolve: Resolve<T>, reject: Reject) => Operation<void>) | ((resolve: Resolve<T>, reject: Reject) => () => void)): Operation<T>
```

### Type Parameters
T


### Parameters


**operation**: (**resolve**: [Resolve](https://frontside.com/effection/api/v3/Resolve.md)&lt;T&gt;, **reject**: [Reject](https://frontside.com/effection/api/v3/Reject.md)) => [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;void&gt; | (**resolve**: [Resolve](https://frontside.com/effection/api/v3/Resolve.md)&lt;T&gt;, **reject**: [Reject](https://frontside.com/effection/api/v3/Reject.md)) => () => void
### 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/instructions.ts#L89)
