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

tasko

v0.3.0

Published

Task sequencer

Downloads

418

Readme

Installation

yarn add tasko
npm install tasko

Terminology

Tasko is inspired by Behavior tree' control flow. It doesn't rely on a time-based execution (tick).

Task creators

A task creator is a function that creates a task.

Parameters

| Properties | Type | Details | | ----------- | -------- | ------------------------------------------------------------------------------- | | success | function | A callback function to notify the parent the task succeeded. | | | | It takes an optional parameter to be propagated which simulate a send call. | | fail | function | A callback function to notify the parent the task failed. | | | | It takes an optional parameter to be propagated which simulate a send call. | | send | function | A function to send something to the parent. | | | | It takes an required parameter to be propagated. |

Returns

A Task.

Tasks

A task is an object which can be run a process and/or be cancelled.

Properties

| Properties | Type | Details | | ---------- | -------- | ------------------------------------------------------------------------- | | name | string | Task name | | run | function | Called by the parent to run the task with optional spread params | | cancel | function | Called by the parent to cancel the task, before or after running the task |

Usage

/**
 * Create a successful task
 *
 * @param {function} success - The callback to succeed with an optional param
 * @param {function} fail - The callback to fail with an optional param
 * @param {function} message - Send a message to the parent
 *
 * @returns {object} - A task
 */
const createSuccessfulTask = (success, fail, send) => ({
  name: 'success',
  run(...params) {
    send(`the task is running with params: ${JSON.stringify(params)}`)
    success('success')
  },
  cancel: () => {
    // noop
  },
})

Decorators

A decorator is a function which enhances the original task behavior.

Parameter

A task creator to enhance.

Returns

A task creator enhanced.

Usage

/**
 * Makes a task always succeeds
 *
 * @param {function} taskCreator - task creator to enhance
 *
 * @returns {function} - Enhanced task creator
 */
const alwaysSucceed = (taskCreator) => (succeed, _, send) => {
  const task = taskCreator(succeed, succeed, send)

  return {
    ...task,
    name: decorateName('alwaysSucceed', task.name), // @alwaysSucceed(task-name)
  }
}

See existing decoractors that you can use import https://github.com/DevSide/tasko/blob/master/src/decorator.js

Composites

A composite (or branch) is a task which orchestrates other tasks with an execution mode and an exit condition.

Execution modes

It determined how a composite task should run its children.

  • serie: one task after another
  • parallel: only works if the tasks run asynchronously, serie otherwise

Exit conditions

It determined how a composite task will succeed or fail based on its children.

  • selector: this task immediately succeeds if a child has succeeded, fails if all its children have failed
  • sequence: this task immediately fails if a child has failed, succeeds if all its children have succeeded
  • all: this task runs all its children, it fails if a child has failed, succeeds otherwise

Parameter

A (spread) list of task creators to execute.

Returns

A task creators.

Available composites

import {
  serieSequence,
  serieSelector,
  serieAll,
  parallelSequence,
  parallelSelector,
  parallelAll,
} from 'tasko/composite'

Usage

import { serieSequence } from 'tasko/composite'
import { noop } from 'tasko/util'

const think = (success, fail, send) => ({
  name: 'think',
  run() {
    send(`I'm thinking`)
    success('Done')
  },
  cancel: noop,
})

const thinkings = serieSequence(think, think)

thinkings(
  () => console.log('Process succeeded !'),
  () => console.log('Process failed !'),

  // composites lift up every child messages sent, the 2nd argument is the unique child name
  (message, taskName) => console.log(taskName + ':', message),
).run()

Logs

think: I'm thinking
think: Done
think: I'm thinking
think: Done
Process succeeded !

More examples