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 🙏

© 2026 – Pkg Stats / Ryan Hefner

taskorama

v2.7.0

Published

Taskorama

Readme

Taskorama is an implementation of the Task data type. It is used to express concurrent, asynchronous and cancellable computations using functional programming constructs.

The semantics is pretty close to the ones provided by Promises but it has many subtle differencies explained in the Rationale section.

Here is an example of how you can use them :

import Task from 'taskorama'

// Let's create a Task
const myTimeoutTask = Task(function (reject, resolve) {

  // complete task succesfully after 3s
  let timer = setTimeout(resolve, 3000)

  // execute `cancel` to stop the timeout
  let cancel = () => clearTimeout(timer)

  return {cancel}
})

// Start `myTimeoutTask`
const myTimeoutExec = myTimeoutTask.fork(
  (rej) => console.log('failure:', rej),
  (res) => console.log('success:', res),
  (err) => console.error('caught error:', err)
)

// Cancel `myTimeoutTask` when you need to !
myTimeoutExec.cancel()

Install

> npm install --save taskorama

or

> yarn add taskorama

or CDN

https://unpkg.com/taskorama

Usage

The full API docs is available here : Taskorama Docs

Creating a Task

const task = Task((resolve, reject) => {
  // Do your thing ...
  resolve(the_result)

  // An error ?
  reject(the_error)

  // A closure that cancels stuff running in the task
  const cancel = () => console.log('cancelled !')

  // return it inside an object
  return {cancel}
})

Running (forking) and cancelling a Task

// the failure handler
const failureEffect = (err) => {}

// the success handler
const successEffect = (res) => {}

// the error handler (optional)
const errorEffect = (res) => {}

// Let's start the task
const runningTask = task.fork(
  failureEffect,
  successEffect,
  errorEffect
)

// Let's cancel it
runningTask.cancel() // --> 'cancelled !'

Rationale

I created this lib when I tried to implement Tasks in JavaScript in order to understand how do they work.

I like using Promises but they have major design flaws IMHO :

  • They run as soon as the promise is declared : what if I want to defer the computation ?
  • They are async by default : i.e. Promise.resolve(2) always runs on the next tick
  • They are not cancellable (it's unfortunate that we can't cancel window.fetch http request when necessary)

Tasks happen to be really simple and have richer semantics than Promises :

  • Tasks are pure : they do not perform any side-effect as long as they are not executed by calling .fork() .
  • Tasks make a clear separation between definition and execution, while Promises mix the two. @andrestaltz explained it way better than me in this comment and this post

So I decided to replace Promises by Tasks in my code in order to separate pure data processing resulting of an async computation and side-effects.

I started this project after watching this talk about Observables.

The internals of Taskorama are similar to the one used in case explained in this video.

License

Taskorama is released under the MIT license. See LICENSE for details.