Skip to content

Lightweight utility that makes it easy to sequentially resolve arrays of promises

License

Notifications You must be signed in to change notification settings

dacre-denny/js-sequmise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sequmise

resolve arrays of promises and asynchronous tasks sequentially

build Coverage Status Downloads


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

About

Lightweight utility that makes it easy to sequentially resolve arrays of promises

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •