Module

Yoga.Om.WorkerBees.SharedInt

Package
purescript-yoga-om-workerbees
Repository
rowtype-yoga/purescript-yoga-om-workerbees

#SharedInt Source

newtype SharedInt

An atomic integer reference backed by SharedArrayBuffer. Can be shared across worker threads via toSendable/fromSendable.

#new Source

new :: Int -> Effect SharedInt

Create a new SharedInt initialized to the given value.

#read Source

read :: SharedInt -> Effect Int

Atomically read the current value.

#write Source

write :: SharedInt -> Int -> Effect Unit

Atomically write a new value.

#add Source

add :: SharedInt -> Int -> Effect Int

Atomically add to the current value. Returns the OLD value.

#sub Source

sub :: SharedInt -> Int -> Effect Int

Atomically subtract from the current value. Returns the OLD value.

#compareAndSwap Source

compareAndSwap :: SharedInt -> Int -> Int -> Effect Int

Atomic compare-and-swap. If current value equals expected, replace with replacement. Returns the old value.

#modify Source

modify :: SharedInt -> (Int -> Int) -> Effect Int

Atomically modify the value using a CAS loop. Retries until the CAS succeeds.

#toSendable Source

toSendable :: SharedInt -> SendWrapper SharedInt

Wrap for sending to a worker thread.

#fromSendable Source

fromSendable :: SendWrapper SharedInt -> SharedInt

Unwrap after receiving on a worker thread.