{"id":17023962,"url":"https://github.com/devside/tasko","last_synced_at":"2025-04-12T10:40:54.989Z","repository":{"id":26258496,"uuid":"107779715","full_name":"DevSide/tasko","owner":"DevSide","description":"Task sequencer","archived":false,"fork":false,"pushed_at":"2024-10-16T17:39:17.000Z","size":1096,"stargazers_count":2,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T05:33:14.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevSide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-21T12:52:39.000Z","updated_at":"2024-10-16T17:38:25.000Z","dependencies_parsed_at":"2023-01-14T04:17:38.868Z","dependency_job_id":null,"html_url":"https://github.com/DevSide/tasko","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevSide%2Ftasko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevSide%2Ftasko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevSide%2Ftasko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevSide%2Ftasko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevSide","download_url":"https://codeload.github.com/DevSide/tasko/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248556685,"owners_count":21124156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T07:14:54.781Z","updated_at":"2025-04-12T10:40:54.968Z","avatar_url":"https://github.com/DevSide.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e\n  Tasko\n\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  Declarative task sequencer for Javascript\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/DevSide/tasko\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/travis/DevSide/tasko/master.svg\" alt=\"Build Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href='https://coveralls.io/github/DevSide/tasko?branch=master' target=\"_blank\"\u003e\n    \u003cimg src='https://img.shields.io/coveralls/github/DevSide/tasko/master.svg' alt='Coverage Status' /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/tasko\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/tasko.svg\" alt=\"NPM Version\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\n```shell\nyarn add tasko\nnpm install tasko\n```\n\n## Terminology\n\nTasko is inspired by Behavior tree' control flow. It doesn't rely on a time-based execution (tick).\n\n### Task creators\n\nA task creator is a function that creates a task.\n\n#### Parameters\n\n| Properties  | Type     | Details                                                                         |\n| ----------- | -------- | ------------------------------------------------------------------------------- |\n| **success** | function | A callback function to notify the parent the task succeeded.                    |\n|             |          | It takes an optional parameter to be propagated which simulate a **send** call. |\n| **fail**    | function | A callback function to notify the parent the task failed.                       |\n|             |          | It takes an optional parameter to be propagated which simulate a **send** call. |\n| **send**    | function | A function to send something to the parent.                                     |\n|             |          | It takes an required parameter to be propagated.                                |\n\n#### Returns\n\nA Task.\n\n### Tasks\n\nA task is an object which can be run a process and/or be cancelled.\n\n#### Properties\n\n| Properties | Type     | Details                                                                   |\n| ---------- | -------- | ------------------------------------------------------------------------- |\n| **name**   | string   | Task name                                                                 |\n| **run**    | function | Called by the parent to run the task with optional spread params          |\n| **cancel** | function | Called by the parent to cancel the task, before or after running the task |\n\n#### Usage\n\n```js\n/**\n * Create a successful task\n *\n * @param {function} success - The callback to succeed with an optional param\n * @param {function} fail - The callback to fail with an optional param\n * @param {function} message - Send a message to the parent\n *\n * @returns {object} - A task\n */\nconst createSuccessfulTask = (success, fail, send) =\u003e ({\n  name: 'success',\n  run(...params) {\n    send(`the task is running with params: ${JSON.stringify(params)}`)\n    success('success')\n  },\n  cancel: () =\u003e {\n    // noop\n  },\n})\n```\n\n### Decorators\n\nA **decorator** is a function which enhances the original task behavior.\n\n#### Parameter\n\nA task creator to enhance.\n\n#### Returns\n\nA task creator enhanced.\n\n#### Usage\n\n```js\n/**\n * Makes a task always succeeds\n *\n * @param {function} taskCreator - task creator to enhance\n *\n * @returns {function} - Enhanced task creator\n */\nconst alwaysSucceed = (taskCreator) =\u003e (succeed, _, send) =\u003e {\n  const task = taskCreator(succeed, succeed, send)\n\n  return {\n    ...task,\n    name: decorateName('alwaysSucceed', task.name), // @alwaysSucceed(task-name)\n  }\n}\n```\n\nSee existing decoractors that you can use import https://github.com/DevSide/tasko/blob/master/src/decorator.js\n\n### Composites\n\nA **composite (or branch)** is a task which orchestrates other tasks with an execution mode and an exit condition.\n\n#### Execution modes\n\nIt determined how a composite task should run its children.\n\n- **serie**: one task after another\n- **parallel**: only works if the tasks run asynchronously, serie otherwise\n\n#### Exit conditions\n\nIt determined how a composite task will succeed or fail based on its children.\n\n- **selector**: this task immediately succeeds if a child has succeeded, fails if all its children have failed\n- **sequence**: this task immediately fails if a child has failed, succeeds if all its children have succeeded\n- **all**: this task runs all its children, it fails if a child has failed, succeeds otherwise\n\n#### Parameter\n\nA (spread) list of task creators to execute.\n\n#### Returns\n\nA task creators.\n\n#### Available composites\n\n```js\nimport {\n  serieSequence,\n  serieSelector,\n  serieAll,\n  parallelSequence,\n  parallelSelector,\n  parallelAll,\n} from 'tasko/composite'\n```\n\n#### Usage\n\n```js\nimport { serieSequence } from 'tasko/composite'\nimport { noop } from 'tasko/util'\n\nconst think = (success, fail, send) =\u003e ({\n  name: 'think',\n  run() {\n    send(`I'm thinking`)\n    success('Done')\n  },\n  cancel: noop,\n})\n\nconst thinkings = serieSequence(think, think)\n\nthinkings(\n  () =\u003e console.log('Process succeeded !'),\n  () =\u003e console.log('Process failed !'),\n\n  // composites lift up every child messages sent, the 2nd argument is the unique child name\n  (message, taskName) =\u003e console.log(taskName + ':', message),\n).run()\n```\n\nLogs\n\n```\nthink: I'm thinking\nthink: Done\nthink: I'm thinking\nthink: Done\nProcess succeeded !\n```\n\n### More examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevside%2Ftasko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevside%2Ftasko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevside%2Ftasko/lists"}