npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tasksf

v1.3.28

Published

Simple tasks manager factory

Downloads

12

Readme

tasksf npm version Build Status Coverage Status devDependencies Status

Simple tasks manager factory

Run your code based on tasks

Run callback tasks, timeout tasks, trigger tasks, async tasks and promise tasks in sequences, loops, parallels and limiters with automatic exception handling. Provides easier way to handle chaining and unchainig of events and actions.

Install:

Install with npm

npm install tasksf

Use standalone

<script src="https://cdn.jsdelivr.net/npm/tasksf/standalone/tasksf.js"></script>
or
<script src="https://cdn.jsdelivr.net/npm/tasksf/standalone/tasksf.min.js"></script>

Access the library:

Import

import { tf } from 'tasksf';

Require

const tasksf = require('tasksf');

Standalone

<script src="https://cdn.jsdelivr.net/npm/tasksf/standalone/tasksf.min.js"></script>
<script>
// global tasksf variable exists
// tasksf.tf - factory
// tasksf.Task - task
// and so on
</script>

Basics:

Tasks

Everythink you make can be a task. A callback with more features.

What is Task, how to create a Task

Task is a set of run, complete and recover callbacks. On task.run() we have run callback executed. When it's complete we have the complete callback executed. Recover is used in case you put your tasks in some collection and the previous task crashes with exceptions. You will receive that exception in recover callback and decide if you want to proceed / run or stop and abort.

// default way
new Task(run, complete, recover)
// quick way
tf.task(run, complete, recover)
// you can skip complete and recover
new Task(run)
tf.task(run)
What is TimeoutTask, how to create a TimeoutTask

Timeout task is a task that runs after timeout. The timeout is in ms. So 5 * 1000 will run after 5 sec. TimeoutTask extends all of the Task functionality. If you skip all callbacks and use the task in a sequential collection it's just waiting interval.

// default way
new TimeoutTask(timeout, run, complete, recover)
// quick way
tf.task(timeout, run, complete, recover)
// you can skip run, complete and recover
new TimeoutTask(timeout)
tf.task(timeout)
What is TriggerTask, how to create a TriggerTask

TriggerTask is a task that never completes alone. It's useful when waiting for something - event, user interaction or something else. It has no run or recover method - and when put in a queue it just waits for task.complete().

// default way
new TriggerTask(complete)
// quick way
tf.task(complete, false)
// you can skip complete
new TriggerTask()
tf.task()
What is AsyncTask, how to create an AsyncTask

Async task is similar to Trigger task, but with run and complete body. Run will execute run callback, but never run complete alone - you need to trigger it yourself. You receive "complete" function as a first parameter.

const run = (complete, self, ...) => {
  // do something
  complete(); // will call complete callback to proceed
};
new AsyncTask(run);
// a shorter way to do the same
new AsyncTask((complete) => { complete(); });
// event shorter way to do that
tf.task((complete) => { complete(); }, 0);
// default set of parameters
new AsyncTask(run, complete, recover)
// quick way
tf.task(run, complete, recover, 0)
// you can skip complete and recover
new AsyncTask(run)
tf.task(run, 0)
What is PromiseTask, how to create an PromiseTask

Promose task is similar to Trigger task, but with complete body. Run will execute and wait for promise finally, but never run complete alone - just wait for a promise. Promise is not handled in any way - it's all up to you to handle then() and catch() in a manner you want. When finally() is invoked the task will try to complete itself. It's useful if you need to queue promises or mix them with tasks.

// default set of parameters
new PromiseTask(promise, complete, recover)
// quick way
tf.task(promise, complete, recover)
// you can skip complete and recover
new PromiseTask(promise)
tf.task(promise)

What are collections

Tasks are useful when ordered in collections. For now we have:

  • sequences
  • loops
  • parallels
  • limits
Tasks in a sequence

Sequence executes tasks one by one.

const task1 = tf.task(
  () => console.log('task 1 run'),
  () => console.log('task 1 complete')
);
const task2 = tf.task(
  () => console.log('task 2 run'),
  () => console.log('task 2 complete')
);

tf.sequence(() => console.log('sequence complete'))
  .push(task1)
  .push(task2)
  .run();

/**
 * Expected output:
 * task 1 run, task 1 complete,
 * task 2 run, task 2 complete,
 * sequence complete
 */
Tasks in a loop

Loop is sequence that repeats.

const task1 = tf.task(
  () => console.log('task 1 run'),
  () => console.log('task 1 complete')
);
const task2 = tf.task(
  () => console.log('task 2 run'),
  () => console.log('task 2 complete')
);

tf.loop(2, () => console.log('loop'))
  .push(task1)
  .push(task2)
  .run();

/**
 * Expected output:
 * task 1 run, task 1 complete,
 * task 2 run, task 2 complete,
 * loop
 * task 1 run, task 1 complete,
 * task 2 run, task 2 complete,
 * loop
 */
Timeout tasks in a parallel

Parallel runs all tasks at once. You can have complete callback on the first or on the last of tasks.

const task1 = tf.task(
  200,
  () => console.log('task 1 run'),
  () => console.log('task 1 complete')
);
const task2 = tf.task(
  100,
  () => console.log('task 2 run'),
  () => console.log('task 2 complete')
);

tf.parallel(() => console.log('parallel complete'))
  .push(task1)
  .push(task2)
  .run();

/**
 * Expected output:
 * task 2 run, task 2 complete,
 * task 1 run, task 1 complete,
 * parallel complete
 */
Timeout tasks in a limiter

Limiter is a parallel with limit of currently running tasks. Default limit is 1.

const task1 = tf.task(
  200,
  () => console.log('task 1 run'),
  () => console.log('task 1 complete')
);
const task2 = tf.task(
  100,
  () => console.log('task 2 run'),
  () => console.log('task 2 complete')
);

tf.limiter(1, () => console.log('limiter complete'))
  .push(task1)
  .push(task2)
  .run();

/**
 * Expected output:
 * task 1 run, task 1 complete,
 * task 2 run, task 2 complete,
 * limiter complete
 */

More examples

Check the examples

Documentation

Check the documentation

What is next

Check the todo

What have changed so far

Check the changelog