---
# System prepended metadata

title: Promise utilities
tags: [zeta-dom]

---

---
tags: zeta-dom
---

# Promise utilities

### `always`

Similar to bind the same function as `then` and `catch` callback.

```typescript
always(promise, callback)
```

###### Example

```typescript
import { always } from "zeta-dom/util"

always(promise, (resolved, result) => {
    toggleSomething(resolved);
});
```

### `resolveAll`

Creates a new promise that aggregates results of other promises.

```typescript
resolveAll(thenable)
resolveAll(arrayOfPromise)
resolveAll(dictOfPromise)
```

###### Example

```typescript
import { resolveAll } from "zeta-dom/util"

let p1 = Promise(1);
let p2 = p1.then(() => 2);
let p3 = 3;

resolveAll({ p1, p2, p3 }, v => {
    console.log(v); // { p1: 1, p2: 2, p3: 3 }
});

// same as Promise.all
resolveAll([p1, p2, p3], v => {
    console.log(v); // [1, 2, 3]
});

// for completeness, same as Promise.resolve
resolveAll(promise);
resolveAll(any);
```

### `catchAsync`

Shorthand for `promise.catch(noop)`.

```typescript
catchAsync(promise)
```

### `setPromiseTimeout`

Creates a promise when will reject or resolve automatically after number of milliseconds, if the given promise is still pending.

```typescript
setPromiseTimeout(promise, milliseconds, resolveOnTimeout?)
```

