Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/altipla-consulting/promises

Promises utilities.
https://github.com/altipla-consulting/promises

Last synced: about 1 month ago
JSON representation

Promises utilities.

Awesome Lists containing this project

README

        

# promises

Promises utilities.

## Install

```sh
npm i @altipla/promises
```

## Usage

### Resolve multiple promises in parallel

```js
import { resolveAll } from '@altipla/promises'

let { foo, bar } = await resolveAll({
foo: client.List(),
bar: otherPromise,
})
```

### Run a Vue event handler with a promise return

Run the action from the component method:

```vue

import { defineComponent } from 'vue'

export default defineComponent({
name: 'my-component',

setup(props, { emit }) {
async function run() {
await runAction(this.$emit)

// If you want to customize the action name or the argument.
await runAction(this.$emit, 'action', value)

// Things you want to run after the promise of the other component is resolved
...
}

return {
run,
}
}
})

```

Then outside the component you can wait for your promise:

```vue

import { defineComponent } from 'vue'

export default defineComponent({
setup(props, { emit }) {
async function foo() {
// Do anything you need, my-component will wait for this before continuing
// with the code after the runAction call.
}

return {
foo,
}
}
}

```