> For the complete documentation index, see [llms.txt](https://docs.corets.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.corets.io/helpers/promise-helpers.md).

# Promise Helpers

Source code is hosted on [GitHub](https://github.com/corets/promise-helpers)

{% tabs %}
{% tab title="yarn" %}

```bash
yarn add @corets/promise-helpers
```

{% endtab %}

{% tab title="npm" %}

```
npm install --save @corets/promise-helpers
```

{% endtab %}
{% endtabs %}

## createTimeout() <a href="#createtimeout" id="createtimeout"></a>

A promisified version of the `setTimeout` function:

```typescript
import { createTimeout } from "@corets/promise-helpers"

await createTimeout(2000)
```

## createPromise() <a href="#createpromise" id="createpromise"></a>

Create a promise that you can pass around without specifying the resolve function upfront:

```typescript
import { createPromise } from "@corets/promise-helpers"

const runWhenResolved = async (promise: Promise<any>) => {
  try {
    const result =  await promise
    console.log("promise resolved with:", result)
  } catch (err) {
    console.error("an error was thrown from promise:", err)
  }
}

const promise = createPromise()

// pass promise to another function
runWhenResolved(promise)

promise.resolve("some data")
// or
promise.reject("reason...")
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.corets.io/helpers/promise-helpers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
