Module

Node.WorkerBees

Package
purescript-node-workerbees
Repository
natefaubion/purescript-node-workerbees

#WorkerContext Source

type WorkerContext a i o = { exit :: Effect Unit, receive :: (i -> Effect Unit) -> Effect Unit, reply :: o -> Effect Unit, threadId :: ThreadId, workerData :: a }

#WorkerThread Source

data WorkerThread t0

#WorkerOptions Source

type WorkerOptions a o = { onError :: Error -> Effect Unit, onExit :: Int -> Effect Unit, onMessage :: o -> Effect Unit, workerData :: a }

#Worker Source

data Worker t0 t1 t2

#ThreadId Source

newtype ThreadId

Constructors

Instances

#threadId Source

#makeAsMain Source

makeAsMain :: forall a i o. Sendable o => WorkerConstructor a i o -> Effect Unit

Implements the worker code that can later be called via the unsafeWorkerFromPath function. This code must be bundled such that main is actually called in the file.

#unsafeWorkerFromPath Source

unsafeWorkerFromPath :: forall a i o. Sendable o => String -> Worker a i o

Builds a new worker given a path to the compiled code constituting the main function that should execute in the worker. The worker code should be created using makeAsMain. The path must be either an absolute path or a relative path that begins with ./ or ../

unsafeWorkerFromPath "./output/My.Bundled.Output/index.js"

#lift Source

lift :: forall e a b. (a -> b) -> WorkerConstructor e a b

#liftReader Source

liftReader :: forall e a b. (a -> Reader e b) -> WorkerConstructor e a b

#liftEffect Source

liftEffect :: forall e a b. (a -> Effect b) -> WorkerConstructor e a b

#liftReaderT Source

liftReaderT :: forall e a b. (a -> ReaderT e Effect b) -> WorkerConstructor e a b

#spawn Source

spawn :: forall a i o. Sendable a => Worker a i o -> WorkerOptions a o -> (Either Error (WorkerThread i) -> Effect Unit) -> Effect Unit

Instantiates a new worker thread. If this worker subscribes to input, it will need to be cleaned up with terminate, otherwise it will hold your process open.

#post Source

post :: forall i. Sendable i => i -> WorkerThread i -> Effect Unit

Sends some input to a worker thread to process.

#terminate Source

terminate :: forall i. WorkerThread i -> (Either Error Unit -> Effect Unit) -> Effect Unit

Terminates the worker thread.

#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

#SendableRowList Source

#SendWrapper Source

newtype SendWrapper a

For newtypes that are otherwise Sendable.

Instances

#wrap Source

wrap :: forall a b. Newtype a b => Sendable b => a -> SendWrapper a

#unsafeWrap Source

unsafeWrap :: forall a. a -> SendWrapper a

Use with care. If you send something that isn't actually Sendable, it will raise an exception.

#unwrap Source

unwrap :: forall a. SendWrapper a -> a