diff --git a/src/Node.Worker.js b/src/Node.Worker.js index d1bc188..ae972f6 100644 --- a/src/Node.Worker.js +++ b/src/Node.Worker.js @@ -14,3 +14,6 @@ export const resourceLimitsImpl = () => worker.resourceLimits /** @type {(a: object) => () => void} */ export const markUntransferableImpl = a => () => worker.markAsUntransferable(a) + +/** @type {() => unknown} */ +export const workerDataImpl = () => worker.workerData diff --git a/src/Node.Worker.purs b/src/Node.Worker.purs index 1b0971c..3c5ce8f 100644 --- a/src/Node.Worker.purs +++ b/src/Node.Worker.purs @@ -1,10 +1,13 @@ -module Node.Worker (ResourceLimits, shareEnv, resourceLimits, isMainThread, threadId, markUntransferable) where +module Node.Worker (ResourceLimits, shareEnv, resourceLimits, isMainThread, threadId, markUntransferable, workerData) where import Prelude +import Control.Monad.Error.Class (liftEither) +import Data.Bifunctor (lmap) import Data.Either (hush) import Data.Maybe (Maybe) import Effect (Effect) +import Effect.Exception (error) import Foreign (Foreign) import Node.Worker.Serializable (class Serializable, deserialize, serialize) @@ -13,6 +16,10 @@ foreign import isMainThread :: Effect Boolean foreign import threadId :: Effect Int foreign import markUntransferableImpl :: Foreign -> Effect Unit +foreign import workerDataImpl :: Effect Foreign + +workerData :: forall a. Serializable a => Effect a +workerData = bind workerDataImpl (liftEither <<< lmap error <<< deserialize) markUntransferable :: forall a. Serializable a => a -> Effect Unit markUntransferable = markUntransferableImpl <<< serialize