All Projects β†’ rpominov β†’ Fun Task

rpominov / Fun Task

Licence: mit
Abstraction for managing asynchronous code in JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fun Task

Fluture
πŸ¦‹ Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+519.56%)
Mutual labels:  monad, async, promise, future, functional-programming
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+150.14%)
Mutual labels:  async, promise, task, future
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-63.36%)
Mutual labels:  monad, async, promise, functional-programming
Unityfx.async
Asynchronous operations (promises) for Unity3d.
Stars: ✭ 143 (-60.61%)
Mutual labels:  async, promise, task, future
Promised Pipe
A ramda.pipe-like utility that handles promises internally with zero dependencies
Stars: ✭ 64 (-82.37%)
Mutual labels:  async, promise, fp
asynqro
Futures and thread pool for C++ (with optional Qt support)
Stars: ✭ 103 (-71.63%)
Mutual labels:  promise, monad, future
Flowa
πŸ”₯Service level control flow for Node.js
Stars: ✭ 66 (-81.82%)
Mutual labels:  async, promise, task
React Organism
Dead simple React state management to bring pure components alive
Stars: ✭ 219 (-39.67%)
Mutual labels:  async, promise, functional-programming
Fasy
FP iterators that are both eager and asynchronous
Stars: ✭ 488 (+34.44%)
Mutual labels:  async, functional-programming, fp
Taskorama
βš™ A Task/Future data type for JavaScript
Stars: ✭ 90 (-75.21%)
Mutual labels:  async, promise, functional-programming
Monio
Async-capable IO monad for JS
Stars: ✭ 311 (-14.33%)
Mutual labels:  monad, functional-programming, fp
Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+1.65%)
Mutual labels:  monad, functional-programming, fp
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+48.21%)
Mutual labels:  monad, functional-programming, fp
Funfix
Functional Programming Library for JavaScript, TypeScript and Flow ✨⚑️
Stars: ✭ 596 (+64.19%)
Mutual labels:  async, functional-programming, fp
Future
Streamlined Future<Value, Error> implementation
Stars: ✭ 291 (-19.83%)
Mutual labels:  async, promise, future
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+47.66%)
Mutual labels:  async, promise, future
Task Easy
A simple, customizable, and lightweight priority queue for promises.
Stars: ✭ 244 (-32.78%)
Mutual labels:  async, promise, task
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (-61.16%)
Mutual labels:  monad, async, promise
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (-46.83%)
Mutual labels:  task, promise, future
Pfps Shopping Cart
πŸ›’ The Shopping Cart application developed in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 262 (-27.82%)
Mutual labels:  functional-programming, fp

fun-task* Build Status Coverage Status

An abstraction for managing asynchronous code in JS.

* The name is an abbreviation for "functional task" (this library is based on many ideas from Functional Programming). The type that library implements is usually referred to in the documentation as just "Task".

Installation

NPM

npm install fun-task
// modern JavaScript
import Task from 'fun-task'

// classic JavaScript
var Task = require('fun-task')

CDN

<script src="https://unpkg.com/fun-task/umd/funTask.js"></script>
<script>
  var Task = window.FunTask
</script>

What is a Task?

Task is an abstraction similar to Promises. The key difference is that a Task represents a computation while a Promise represents only a result of a computation. If we have a Task we can: start the computation; terminate it before it's finished; or wait until it finishes, and get the result. While with a Promise we can only get the result. This difference doesn't make Tasks better, they are just different, we can find legitimate use cases for both abstractions. Let's review it again:

If we have a Task:

  • We can start the computation that it represents (e.g. a network request)
  • We can choose not to start the computation and just throw task away
  • We can start it more than once
  • While computation is running, we can notify it that we're not interested in the result any more, and as a response computation may choose to terminate itself
  • When computation finishes we get the result

If we have a Promise:

  • Computation is already running (or finished) and we don't have any control of it
  • We can get the result whenever it's ready
  • If two or more consumers have a same Promise they all will get the same result

The last item is important. This might be an advantage of Promises over Tasks. If two consumers have a same Task, each of them have to spawn their own instance of the computation in order to get the result, and they may even get different results.

What is a computation?

function computation(onSuccess, onFailure) {
  // ...
  return () => {
    // ... cancellation logic
  }
}

From Task API perspective, computation is a function that accepts two callbacks. It should call one of them after completion with the final result. Also a computation may return a function with cancellation logic, or it can return undefined if particular computation has no cancellation logic.

Creating a Task from a computation is easy, we just call task = Task.create(computation). This is very similar to new Promise(computation), but Task won't execute computation immediately, the computation starts only when task.run() is called.

Documentation

Flow

The NPM package ships with Flow definitions. So you can do something like this if you use Flow:

// @flow

import Task from 'fun-task'

function incrementTask<F>(task: Task<number, F>): Task<number, F> {
  return task.map(x => x + 1)
}

Specifications compatibility

Task is compatible with Fantasy Land and Static Land implementing:

Development

npm run lobot -- --help

Run lobot commands as npm run lobot -- args...

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].