1.0.10 • Published 3 years ago

sequmise v1.0.10

Weekly downloads
18
License
MIT
Repository
github
Last release
3 years ago

Quick Start

Installation

npm install sequmise

Basic Usage

import sequmise from 'sequmise';

/* Execute multiple asynchronous tasks by array */
const [ session, asyncResult, syncResult ] = await sequmise([ fetch('/session'), asyncTask, syncTask ])

/* Execute multiple asynchronous tasks by arguments */
const [ jsonAll, jsonOne ] = await sequmise(fetch('/get/all'), fetch('/get/one'))

Introduction

sequmise is a zero dependency utility that simplifies sequential execution of multiple promises/asynchronous tasks.

When all supplied tasks execute successfully, sequmise returns a single array containing the result of each task. The order of results in the returned array matches the order that tasks were executed. If any task throws an exception or is rejected, this behavior will be propagated by sequmise.

With no external dependencies and a simple, flexible API, sequmise is a useful tool to have on hand for your next project.

Advanced Usage

Support for value, sync and async task combinations:

/* Resolve values, sync and async tasks, returning the resolved values in order */
const results = await sequmise([
  'hello world',        // resolves to 'hello world'
  fetch('/session'),    // resolves to { session : '123' }
  fetch('/username'),   // resolves to { username : 'John Smith' }
])

assert.deepEqual(results, [
  'hello world',
  { session : '123' },
  { username : 'John Smith' }
])

Support for nested value, sync and async task combinations:

/* Resolve nested arrays, maintaining nested order and hierarchy */
const results = await sequmise([
  [
    fetch('/session'),  // resolves to { session : '123' }
    fetch('/user')      // resolves to { username : 'John Smith' }
  ],
  [
    123,                // resolves to 123,
    createAsyncTask()   // resolves to { testing : 123 }
  ]
])

assert.deepEqual(results, [
  [
    { session : '123' },
    { username : 'John Smith' }
  ],
  [
    123,
    { testing : 123 }
  ]
])

Support for value, sync and async tasks to be specified via multiple arguments/spreading:

const results = await sequmise(123,
  asyncReturn('goodbye'),
  'test',
  asyncReturn('moon'))

assert.deepEqual(results, [
  123,
  'goodbye'
  'test'
  'moon'
])

Run tests

npm run test
1.0.9

3 years ago

1.0.8

3 years ago

1.0.10

3 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago