项目作者: metarhia

项目描述 :
Simplest way to manage asynchronicity
高级语言: JavaScript
项目地址: git://github.com/metarhia/do.git
创建时间: 2013-01-30T20:44:21Z
项目社区:https://github.com/metarhia/do

开源协议:MIT License

下载


“do” is the simplest way to manage asynchronicity

CI Status
NPM Version
NPM Downloads/Month
NPM Downloads

If you don’t want to use all the async/chain libraries but just want a reliable way to know when the function is done - this is for you.

Installation

npm i do

Usage

Series async execution

  1. const chain = require('do');
  2. const c1 = chain
  3. .do(readConfig, 'myConfig')
  4. .do(selectFromDb, 'select * from cities')
  5. .do(getHttpPage, 'http://kpi.ua')
  6. .do(readFile, 'README.md');
  7. c1((err, result) => {
  8. console.log('done');
  9. if (err) console.log(err);
  10. else console.dir({ result });
  11. });

Data collector

  1. const chain = require('do');
  2. const fs = require('fs');
  3. const dc = chain.do(6);
  4. dc('user', null, { name: 'Marcus Aurelius' });
  5. fs.readFile('HISTORY.md', (err, data) => dc.collect('history', err, data));
  6. fs.readFile('README.md', dc.callback('readme'));
  7. fs.readFile('README.md', dc('readme'));
  8. dc.take('readme', fs.readFile, 'README.md');
  9. setTimeout(() => dc.pick('timer', { date: new Date() }), 1000);

Run tests

npm test

License & Contributors

Copyright (c) 2013-2023 do contributors.
See github for full contributors list.
Do is MIT licensed.