@@ -3,6 +3,7 @@ module Yoga.Om.WorkerBees
3 , PoolConfig
3 , PoolConfig
4 , defaultPoolConfig
4 , defaultPoolConfig
6 , terminatePool
7 , terminatePool
7 , distributeWork
8 , distributeWork
8 , module Exports
9 , module Exports
@@ -41,20 +42,28 @@ defaultPoolConfig workerPath =
41type WorkerPool input output = Pool.WorkerPool input output
42type WorkerPool input output = Pool.WorkerPool input output
43-- | Create a worker pool. Must be paired with `terminatePool`.
44-- | Create a worker pool. Must be paired with `terminatePool`.
44−-- | Workers receive the current Om context via `ctx.workerData`.
45−-- | If you don't need shared data, use `Unit` as the context type.
47 :: forall ctx errs input output
46 :: forall ctx errs input output
48 . WB.Sendable input
47 . WB.Sendable input
49 => WB.Sendable output
48 => WB.Sendable output
51 => PoolConfig
49 => PoolConfig
52 -> Om ctx errs (WorkerPool input output)
50 -> Om ctx errs (WorkerPool input output)
53−makePool config = do
51+makePool config = Om.fromAff do
54− ctx <- Om.ask
52+ let worker = WB.unsafeWorkerFromPath config.workerPath
53+ Pool.make worker unit config.numWorkers
55+-- | Create a worker pool with shared data accessible to all workers via `workerData`.
57+ :: forall ctx errs input output a
59+ => WB.Sendable output
63+ -> Om ctx errs (WorkerPool input output)
55− Om.fromAff do
64+makePoolWithData config workerData = Om.fromAff do
56− let worker = WB.unsafeWorkerFromPath config.workerPath
65+ let worker = WB.unsafeWorkerFromPath config.workerPath
57− Pool.make worker ctx config.numWorkers
66+ Pool.make worker workerData config.numWorkers
59-- | Terminate a worker pool and all its threads.
68-- | Terminate a worker pool and all its threads.
60terminatePool
69terminatePool