Skip to content

natefaubion/purescript-node-workerbees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-node-workerbees

An opinionated, convenient set of bindings to Node's worker_threads API. Use workerbees to distribute work over multiple actual threads instead of that fiber bullshit Aff gives you.

Also, there's has an Aff-based API that makes it even more convenient.

Example

import Prelude

import Data.Array as Array
import Effect (Effect)
import Effect.Aff as Aff
import Effect.Class.Console as Console
import Node.WorkerBees (Worker)
import Node.WorkerBees as Worker
import Node.WorkerBees.Aff.Pool as WorkerPool

worker :: Worker Unit Int String
worker = Worker.make (Worker.lift ?doSomethingReallyExpensive)

main :: Effect Unit
main = Aff.launchAff_ do
  -- Distributes work over 4 threads.
  res <- WorkerPool.poolTraverse worker unit 4 (Array.range 1 100)
  Console.logShow res

Caveats

  • Workers must be top-level, with no other constraints or arguments.
  • Workers must be exported.
  • Your Node app must not be bundled.

These invariants will be validated at runtime, and if they aren't met will result in a runtime exception.

About

Convenient multi-threading on Node with PureScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published