feat: workerdata

This commit is contained in:
orion 2023-12-24 13:17:34 -06:00
parent 2a4892ce9c
commit 30eed65e65
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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