@task.flow/thread-pool
v0.2.3
Published
Thread pool scheduler for task.flow
Downloads
5
Maintainers
Readme
@task.flow/thread-pool
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