@task.flow/thread-pool

0.2.3 • Public • Published

@task.flow/thread-pool

travis package downloads styled with prettier

Thread pool scheduler for task.flow tasks. You will need to use this or an alternative scheduler to run tasks.

Usage

import Task from "task.flow"
import ThreadPool from "@task.flow/thread-pool"

const get = (url: string): Task<HTTPError, ArrayBuffer> =>
  Task.io(
    (succeed, fail) => {
      var request = new XMLHttpRequest()
      request.addEventListener("load", () => {
        succeed(request.response)
      })
      request.addEventListener("error", () => {
        fail(new HTTPError(request))
      })
      request.responseType = "arraybuffer"
      request.open("GET", url)
      request.send()
      return request
    },
    request => {
      request.abort()
    }
  )

// Note: Type checker only allows spawning Task<empty, void> so following won't
// type check.
// ThreadPool.spawn(get(myURL))

const task = get(myURL)
  .chain(content => {
    console.log("Completed HTTP GET:", content)
    return Task.succeed()
  })
  .capture(error => {
    console.error("Failed HTTP GET", error)
    return Task.succeed()
  })

ThreadPool.spawn(task)

Install

npm install @task.flow/thread-pool

Package Sidebar

Install

npm i @task.flow/thread-pool

Weekly Downloads

5

Version

0.2.3

License

MIT

Unpacked Size

40.2 kB

Total Files

23

Last publish

Collaborators

  • gozala