Module

Effect.Worker

Package
purescript-workly
Repository
cakekindel/purescript-workly

Module defining the Worker type and a low-level API for interacting with worker threads.

#Worker Source

data Worker :: Type -> Type -> Type

Type binding for the Worker class, parameterized over the request (up) and response (dn) object types.

MDN

Instances

#sendMsg Source

sendMsg :: forall up dn. Worker up dn -> up -> Effect Unit

Low-level binding for Worker#postMessage

This will cause a listener attached in the child module (by way of Worker.Child.onMsg) to fire with this message.

If possible, it is recommended to use Effect.Aff.Worker.Channel instead of this low-level API.

MDN

import Effect.Worker (Worker, sendMsg)

worker :: Worker String _

sendMsg "hello" worker

#onMsg Source

onMsg :: forall up dn. Worker up dn -> (MessageEvent dn -> Effect Unit) -> Effect Unit

Low-level binding for attaching a listener to Worker#onmessage.

Any previously attached listener will be removed.

If possible, it is recommended to use Effect.Aff.Worker.Channel instead of this low-level API.

MDN

import Effect.Worker (Worker, onMsg)
import Effect.Console (log)

worker :: Worker _ String

onMsg (\m -> log m) worker