GithubHelp home page GithubHelp logo

done-criteria's Introduction

done-criteria

Build Status

Easy to use async.whilst like utility.

install

$ npm install done-criteria

examples

unnamed

var DoneCriteria = require('../lib/done-criteria')
  , exit = false;

var doneCriteria = new DoneCriteria(['unko', 'geri'], function(error) {
  console.log('all done!');
  exit = true;
});

setTimeout(function() { doneCriteria.done('unko'); }, 1000);
setTimeout(function() { doneCriteria.done('geri'); }, 2000);

var loop = function() {
  if (exit) {
    process.exit(0);
  } else {
    console.log('not done yet...');
    setTimeout(loop, 500);
  }
};
loop();

This code results in:

$ node examples/unnamed.js
not done yet...
not done yet...
not done yet...
not done yet...
all done!

named

var DoneCriteria = require('../lib/done-criteria')
  , exit = false;

var doneCriteria = new DoneCriteria(
    {
        'eat': [
            ['get ingredients', 'cook']
          , function(name) { console.log('%s is done', name); }
        ]
      , 'clean up': [
            ['put dishes into sink', 'wash them']
          , function(name) { console.log('%s is done', name); }
        ]
    }
  , function(error) {
      console.log('all done!');
      exit = true;
    }
);

setTimeout(function() { doneCriteria.done('eat', 'cook'); }, 200);
setTimeout(function() { doneCriteria.done('eat', 'get ingredients'); }, 600);

setTimeout(function() { doneCriteria.done('clean up', 'put dishes into sink'); }, 400);
setTimeout(function() { doneCriteria.done('clean up', 'wash them'); }, 1000);

var loop = function() {
  if (exit) {
    process.exit(0);
  } else {
    console.log('not done yet...');
    setTimeout(loop, 500);
  }
};
loop();

This code will result in:

$ node examples/named.js
not done yet...
not done yet...
eat is done
clean up is done
all done!

count

var DoneCriteria = require('../lib/done-criteria')
  , exit = false;

var doneCriteria = new DoneCriteria(3, function(error) {
  console.log('all done!');
  exit = true;
});

setTimeout(function() { doneCriteria.done(); }, 200);
setTimeout(function() { doneCriteria.done(); }, 400);
setTimeout(function() { doneCriteria.done(); }, 600);

var loop = function() {
  if (exit) {
    process.exit(0);
  } else {
    console.log('not done yet...');
    setTimeout(loop, 500);
  }
};
loop();

This code will result in:

$ node examples/count.js
not done yet...
not done yet...
all done!

License

MIT

done-criteria's People

Contributors

atsuya avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aselmajt

done-criteria's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.