Detalhes do pacote

micro-tasks

pflannery15GNU GPL v30.0.0

Simple task utility that runs tasks as micro tasks via promises.

micro task, tasks, promise

readme (leia-me)

Micro Tasking Library

Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Gratipay donate button

Simple task utility that runs tasks as micro tasks via promises.

Install

NPM

  • Use: require('micro-tasks')
  • Install: npm install --save micro-tasks

Bower

  • Use: require('micro-tasks')
  • Install: bower install micro-tasks

Documentation

Library API

Usage

Single micro tasks

  // creates a MicroTaskQueue, then passes in some optional data
  var data = 0;
    queue = new MicroTaskQueue(data);

  // the following functions are added in no specific order

  // adds a single micro task
  queue.addTask(function(data) {
    console.log("task " + data);
    return data + 1;
  })
  // optional done handler called when all tasks are complete
  .done(function(result) {
    if (result instanceof Error)
      console.error(result)
    else
      console.log("complete " + result);
  });

  queue.run(data);

Multiple micro tasks

  // creates a MicroTaskQueue, then passes in some optional data
  var data = 1,
    queue = new MicroTaskQueue();

  // adds a batch of micro tasks
  queue.addTasks([
    function(data) {
      console.log("task " + data);
      return data + 1;
    },
    function(data) {
      console.log("task " + data);
      return data + 1;
    },
    function(data) {
      console.log("task " + data);
      return data + 1;
    }
  ])
  // optional done handler called when all tasks are complete
  .done(function(result) {
    if (result instanceof Error)
      console.error(result)
    else
      console.log("complete " + result);
  });

  queue.run(data);

Monitoring single tasks

// create a MonitoredTaskQueue, this example passes in some optional data
var data = 0;
var queue = new MonitoredTaskQueue();

// the following functions are added in no specific order

// optional beforeEach task handler
queue.beforeEach(function (data) {
  return data + 1;
})
// optional afterEach task handler
.afterEach(function (data) {
  return data + 1;
})
// adds a task with a taskDone callback handler
.addTask(function (data) {
  return data + 1;
}, function taskDone(data) {
  return data + 1;
})
// optional done handler called when all tasks are complete
.done(function (result) {
  if (result instanceof Error)
    console.error(result)
  else
    console.log("complete " + result);
});

queue.run(data);

Monitoring task batches

  var data = 0;
  // create a MonitoredTaskQueue, this example passes in some optional data
  var queue = new MonitoredTaskQueue();

  // the following functions are added in no specific order

  // optional beforeEach task handler
  queue.beforeEach(function (data) {
    return data + 1;
  })
  // optional afterEach task handler
  .afterEach(function (data) {
    return data + 1;
  })
  // adds a batch of tasks with a taskBatchDone callback handler
  // which is called once the batch of tasks are complete
  .addTasks([
    function (data) {
      return data + 1;
    },
    function (data) {
      return data + 1;
    },
    function (data) {
      return data + 1;
    }
  ], function taskBatchDone(data) {
    return data + 1;
  })
  // optional done handler called when all tasks are complete
  .done(function (result) {
    if (result instanceof Error)
      console.error(result)
    else
      console.log("complete " + result);
  });

  queue.run(data);

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Gratipay donate button

Contributors

These amazing people have contributed code to this project:

Become a contributor!

License

Licensed under GNU GPL v3

Copyright © 2015+ pflannery (https://github.com/pflannery)

Analytics