Module

Yoga.Om.WorkerBees

Package
purescript-yoga-om-workerbees
Repository
rowtype-yoga/purescript-yoga-om-workerbees

#WorkerPool Source

type WorkerPool input output = WorkerPool input output

Worker pool handle

#PoolConfig Source

type PoolConfig = { numWorkers :: Int, workerPath :: String }

Configuration for a worker pool

#defaultPoolConfig Source

defaultPoolConfig :: String -> PoolConfig

Default pool configuration (4 workers)

#makePool Source

makePool :: forall ctx errs input output. Sendable input => Sendable output => PoolConfig -> Om ctx errs (WorkerPool input output)

Create a worker pool. Must be paired with terminatePool.

#makePoolWithData Source

makePoolWithData :: forall ctx errs input output a. Sendable input => Sendable output => Sendable a => PoolConfig -> a -> Om ctx errs (WorkerPool input output)

Create a worker pool with shared data accessible to all workers via workerData.

#terminatePool Source

terminatePool :: forall ctx errs input output. WorkerPool input output -> Om ctx errs Unit

Terminate a worker pool and all its threads.

#distributeWork Source

distributeWork :: forall ctx errs f input output. Traversable f => Sendable input => WorkerPool input output -> f input -> Om ctx errs (f output)

Distribute work across the worker pool in parallel. Each input is submitted to the pool and processed by the next available worker.

Re-exports from Node.WorkerBees

#Worker Source

data Worker t0 t1 t2

#Sendable Source

class Sendable (a :: Type) 

Only Sendable things can be sent back and forth between a worker thread and its parent. These include things that are represented by JavaScript primitives. Arbitrary PureScript values cannot be sent, but variants, records and newtypes of these things can. If you have a newtype of some Sendable, you must wrap it.

Instances

Re-exports from Yoga.Om.WorkerBees.SharedInt

#SharedInt Source

newtype SharedInt

An atomic integer reference backed by SharedArrayBuffer. Can be shared across worker threads via toSendable/fromSendable.

Re-exports from Yoga.Om.WorkerBees.SharedMap

#SharedMap Source

newtype SharedMap a

A shared concurrent map backed by SharedArrayBuffer with striped locks. Keys are Strings, values must be JSON-serializable. The keyspace is split into N segments for N-way concurrency.

Re-exports from Yoga.Om.WorkerBees.SharedState

#SharedState Source

newtype SharedState a

Buffer layout:

  • Int32 slot 0 (bytes 0..3): mutex lock (0 = unlocked, 1 = locked)
  • Int32 slot 1 (bytes 4..7): data length in bytes
  • Bytes 8..N: UTF-8 encoded JSON string A shared mutable state that can be accessed from multiple worker threads. Values are JSON-serialized into a SharedArrayBuffer with a spinlock mutex.