# action

```ts
function action<T>(executor: Executor<T>, desc?: string): Operation<T>
```

Create an [Operation](https://frontside.com/effection/api/v4/Operation.md) that can be either resolved (or
rejected) with a synchronous callback. This is the Effection
equivalent of `new Promise()`. Actions are stateless and so unlike
the `new Promise()` executor function, the action executor is
called every time that an action is evaluated.

The resolver must return a "finally" function that will _always_ be
called regardless of whether the action was resolved or rejected,
or discarded.

### Examples
#### Example 1
```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


### Parameters


**executor**: Executor&lt;T&gt;


a function called every time that an action is evaluated


**desc**<span class="inline-block bg-sky-100 rounded px-2 text-sm text-sky-900 mx-1">optional</span>: string
### Return Type


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


an operation that will run according to `executor` every time it is evaluated

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/action.ts#L49)
