{"id":18747935,"url":"https://github.com/yannickdot/taskorama","last_synced_at":"2025-04-12T22:34:25.307Z","repository":{"id":65514782,"uuid":"78060342","full_name":"YannickDot/Taskorama","owner":"YannickDot","description":"⚙ A Task/Future data type for JavaScript","archived":false,"fork":false,"pushed_at":"2018-06-23T20:36:51.000Z","size":238,"stargazers_count":89,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T23:18:07.915Z","etag":null,"topics":["async","functional-programming","javascript","promise","tasks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YannickDot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-04T23:08:48.000Z","updated_at":"2023-04-18T07:34:02.000Z","dependencies_parsed_at":"2023-01-26T21:05:17.634Z","dependency_job_id":null,"html_url":"https://github.com/YannickDot/Taskorama","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YannickDot%2FTaskorama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YannickDot%2FTaskorama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YannickDot%2FTaskorama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YannickDot%2FTaskorama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YannickDot","download_url":"https://codeload.github.com/YannickDot/Taskorama/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248642308,"owners_count":21138350,"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":["async","functional-programming","javascript","promise","tasks"],"created_at":"2024-11-07T16:32:02.565Z","updated_at":"2025-04-12T22:34:24.990Z","avatar_url":"https://github.com/YannickDot.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n\n  \u003cp align=\"center\"\u003e\n   \u003cbr/\u003e\n   \u003cimg src=\"https://cdn.jsdelivr.net/emojione/assets/svg/2699.svg\" width=\"150\" height=\"150\" alt=\"Taskorama\"\u003e\n   \u003cbr/\u003e\n  \u003c/p\u003e\n  \u003ch1 align=\"center\"\u003eTaskorama\u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\n    \u003cb align=\"center\"\u003eTaskorama is a Task/Future data type for JavaScript\u003c/b\u003e\n  \u003c/p\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.org/package/taskorama\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/taskorama.svg?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e \u003ca href=\"https://github.com/YannickDot/taskorama/blob/master/LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat\" alt=\"licence\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\nTaskorama is an implementation of the Task data type.\nIt is used to express **concurrent**, **asynchronous** and **cancellable computations** using **functional programming** constructs.\n\nThe semantics is pretty close to the ones provided by Promises but it has many subtle differencies explained in the [Rationale](#rationale) section.\n\nHere is an example of how you can use them :\n\n```js\nimport Task from 'taskorama'\n\n// Let's create a Task\nconst myTimeoutTask = Task(function (reject, resolve) {\n\n  // complete task succesfully after 3s\n  let timer = setTimeout(resolve, 3000)\n\n  // execute `cancel` to stop the timeout\n  let cancel = () =\u003e clearTimeout(timer)\n\n  return {cancel}\n})\n\n// Start `myTimeoutTask`\nconst myTimeoutExec = myTimeoutTask.fork(\n  (rej) =\u003e console.log('failure:', rej),\n  (res) =\u003e console.log('success:', res),\n  (err) =\u003e console.error('caught error:', err)\n)\n\n// Cancel `myTimeoutTask` when you need to !\nmyTimeoutExec.cancel()\n\n```\n\n\u003cp align=\"center\"\u003eIt's like a Promise but \u003cstrong\u003epure\u003c/strong\u003e, \u003cstrong\u003edeferrable\u003c/strong\u003e and \u003cstrong\u003ecancellable\u003c/strong\u003e 🤗 \u003c/p\u003e\n\n\n## Install\n\n```sh\n\u003e npm install --save taskorama\n```\n\nor\n\n```sh\n\u003e yarn add taskorama\n```\n\nor CDN\n\n```\nhttps://unpkg.com/taskorama\n```\n\n## Usage\n\n_The full API docs is available here : [Taskorama Docs](https://github.com/YannickDot/taskorama/wiki/API)_\n\n### Creating a Task\n\n```js\nconst task = Task((resolve, reject) =\u003e {\n  // Do your thing ...\n  resolve(the_result)\n\n  // An error ?\n  reject(the_error)\n\n  // A closure that cancels stuff running in the task\n  const cancel = () =\u003e console.log('cancelled !')\n\n  // return it inside an object\n  return {cancel}\n})\n```\n\n### Running (forking) and cancelling a Task\n\n```js\n// the failure handler\nconst failureEffect = (err) =\u003e {}\n\n// the success handler\nconst successEffect = (res) =\u003e {}\n\n// the error handler (optional)\nconst errorEffect = (res) =\u003e {}\n\n// Let's start the task\nconst runningTask = task.fork(\n  failureEffect,\n  successEffect,\n  errorEffect\n)\n\n// Let's cancel it\nrunningTask.cancel() // --\u003e 'cancelled !'\n\n```\n\n# Rationale\n\nI created this lib when I tried to implement Tasks in JavaScript in order to understand how do they work.\n\nI like using Promises but they have major design flaws IMHO :\n\n- They run as soon as the promise is declared : what if I want to defer the computation ?\n- They are **async by default** : i.e. `Promise.resolve(2)` ***always*** runs on the next tick\n- They are not cancellable (it's unfortunate that we can't cancel `window.fetch` http request when necessary)\n\nTasks happen to be really simple and have richer semantics than Promises :\n\n- Tasks are pure : they do not perform any side-effect as long as they are not executed by calling `.fork()` .\n- Tasks make a clear separation between **definition** and **execution**, while Promises mix the two. **@andrestaltz** explained it way better than me in [this comment](https://gist.github.com/jakearchibald/199f4e44880aa07c0b78f025238d14ed#gistcomment-2014667) and [this post](https://staltz.com/promises-are-not-neutral-enough.html)\n\nSo 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.\n\nI started this project after watching [this talk](https://www.youtube.com/watch?v=uQ1zhJHclvs) about Observables.\n\nThe internals of Taskorama are similar to the one used in case explained in this video.\n\n\n## License\n\nTaskorama is released under the MIT license. See LICENSE for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannickdot%2Ftaskorama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannickdot%2Ftaskorama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannickdot%2Ftaskorama/lists"}