@@ -3,6 +3,7 @@ module Yoga.Om.WorkerBees
33 , PoolConfig
44 , defaultPoolConfig
55 , makePool
6+ , makePoolWithData
67 , terminatePool
78 , distributeWork
89 , module Exports
@@ -41,20 +42,28 @@ defaultPoolConfig workerPath =
4142type WorkerPool input output = Pool.WorkerPool input output
4243
4344-- | 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.
4645makePool
4746 :: forall ctx errs input output
4847 . WB.Sendable input
4948 => WB.Sendable output
50− => WB.Sendable ctx
5149 => PoolConfig
5250 -> Om ctx errs (WorkerPool input output)
53−makePool config = do
54− ctx <- Om.ask
55− Om.fromAff do
56− let worker = WB.unsafeWorkerFromPath config.workerPath
57− Pool.make worker ctx config.numWorkers
51+makePool config = Om.fromAff do
52+ let worker = WB.unsafeWorkerFromPath config.workerPath
53+ Pool.make worker unit config.numWorkers
54+
55+-- | Create a worker pool with shared data accessible to all workers via `workerData`.
56+makePoolWithData
57+ :: forall ctx errs input output a
58+ . WB.Sendable input
59+ => WB.Sendable output
60+ => WB.Sendable a
61+ => PoolConfig
62+ -> a
63+ -> Om ctx errs (WorkerPool input output)
64+makePoolWithData config workerData = Om.fromAff do
65+ let worker = WB.unsafeWorkerFromPath config.workerPath
66+ Pool.make worker workerData config.numWorkers
5867
5968-- | Terminate a worker pool and all its threads.
6069terminatePool