Package IO/THREAD-EXCEPTIONS
Types
SYNCHRONOUSTHREADEXCEPTION TYPE · src
Exceptions that a thread raises whenever it encounters a threading related problem. Unlike ThreadingException, these are actual exceptions.
THREADINGEXCEPTION TYPE · src
Thread exception sent asynchronously between threads. This type isn't really an exception, it's more of a message.
UNMASKFINALLYMODE TYPE · src
When a thread unmasks and calls a cleanup operation, the thread is either: * Still running, and will cleanup and continue * Received a stop while it was masked, and will cleanup and then terminate itself.
Package IO/EXCEPTION
Classes
MonadException CLASS · src
Monad :A ⇒ MonadException :AA Monad that can raise and handle exceptions. IMPORTANT: Any MonadException must catch and wrap all unhandled errors inside a wrap-io call as an UnhandledError. See utils/catch-thunk.
Methods:RAISE :: (RuntimeRepr :A) (Signalable :A) ⇒ (:A → (:B :C))
Raise an exception.RAISE-DYNAMIC :: (Dynamic → (:A :B))
Raise an exception wrapped in a Dynamic. Mainly useful to hand-off eexceptions between IO instances.RERAISE :: ((:A :B) → (Unit → (:A :C)) → (:A :B))
Run an operation, run a catch operation if the first operation raised, then re-raise the exception. If the catch operation raises, that exception will be emitted instead of the original exception.HANDLE :: RuntimeRepr :A ⇒ ((:B :C) → (:A → (:B :C)) → (:B :C))
Run an operation, immediately handling if it raised an exception that matches :e.HANDLE-ALL :: ((:A :B) → (Unit → (:A :B)) → (:A :B))
Run an operation, immediately handling any exceptions raised.TRY-DYNAMIC :: ((:A :B) → (:A (Result Dynamic :B)))
Bring any unhandled exceptions into a Result wrapped in Dynamic.
Instances
MonadException IO(MonadException :A) (MonadIo :A) ⇒ MonadException (STM :A)MonadException :A ⇒ MonadException ((EnvT :B) :A)MonadException :A ⇒ MonadException ((StateT :B) :A)
Values
(RAISE-RESULT-DYNAMIC OP) FUNCTION · src
∀ :A :B. MonadException :A ⇒ ((:A (Result Dynamic :B)) → (:A :B))(RAISE-RESULT IO-RES) FUNCTION · src
∀ :A :B :C. (MonadException :A) (RuntimeRepr :B) (Signalable :B) ⇒ ((:A (Result :B :C)) → (:A :C))Raise any (Err :e) into :m. Useful if (Err :e) represents any unhandleable, fatal exception to the program.
(WRAP-ERROR_ THUNK) FUNCTION · src
∀ :A :B. MonadException :B ⇒ ((Unit → :A) → (:B :A))Run thunk, catching any unhandled Lisp/Coalton errors and raising them as exceptions.
(TRY-ALL OP) FUNCTION · src
∀ :A :B. MonadException :A ⇒ ((:A :B) → (:A (Optional :B)))Bring the result of OP up into an Optional. Returns None if OP raised any exceptions.
(TRY OP) FUNCTION · src
∀ :A :B :C. (MonadException :A) (RuntimeRepr :C) ⇒ ((:A :B) → (:A (Result :C :B)))Bring any unhandled exceptions of type :e up into a Result. Continues to carry any unhandeld exceptions not of type :e.
Package IO/MONAD-IO
Classes
UnliftIo CLASS · src
(MonadIo :A) (LiftIo :B :A) ⇒ UnliftIo :A :BMethods:
WITH-RUN-IN-IO :: ((((:A :B) → (:C :B)) → (:C :D)) → (:A :D))
MonadIo CLASS · src
Monad :A ⇒ MonadIo :AMethods:
WRAP-IO_ :: ((Unit → :A) → (:B :A))
Wrap a (potentially) side-effectful function in the monad.
Instances
BaseIo CLASS · src
MonadIo :A ⇒ BaseIo :AA 'base' IO implementation, which can be run to execute some (potentially side-effectful) operation.
Methods:RUN! :: ((:A :B) → :B)
Run a (potentially) side-effectful operation. Throws any unhandled exceptions.RUN-HANDLED! :: ((:A :B) → (Result Dynamic :B))
Run a (potentially) side-effectful operation. Returns any unhandled exceptions as an (Err e).
LiftIo CLASS · src
(Monad :A) (BaseIo :B) ⇒ LiftIo :B :AMethods:
LIFT-IO :: BaseIo :A ⇒ ((:A :B) → (:C :B))
Values
(MAP-INTO-IO ITR A->RB) FUNCTION · src
∀ :A :B :C :D :E :F. (UnliftIo :D :A) (LiftTo :D :F) (IntoIterator :B :C) ⇒ (:B → (:C → (:D :E)) → (:F (List :E)))Efficiently perform a monadic operation for each element of an iterator and return the results. If you're having inference issues, try map-into-io_
(FOREACH-IO ITR A->MB) FUNCTION · src
∀ :A :B :C :D :E :F. (UnliftIo :D :A) (LiftTo :D :F) (IntoIterator :B :C) ⇒ (:B → (:C → (:D :E)) → (:F Unit))Efficiently perform a monadic operation for each element of an iterator. If you're having inference issues, try foreach-io_.
Package IO/SIMPLE-IO
Values
(RAISE-DYNAMIC-IO DYN) FUNCTION · src
∀ :A. (Dynamic → (IO :A))(WITH-RUN-IN-IO_) FUNCTION · src
∀ :A :B :C. UnliftIo :A IO ⇒ ((((:A :B) → (IO :B)) → (IO :C)) → (:A :C))`with-run-in-io`, but pegged to the simple-io implementation. Useful when you need to unlift, run, then immediately re-run a function. See, e.g., io-file:with-open-file%.
(TRY-DYNAMIC-IO IO-OP) FUNCTION · src
∀ :A. ((IO :A) → (IO (Result Dynamic :A)))(HANDLE-ALL-IO IO-OP HANDLE-OP) FUNCTION · src
∀ :A. ((IO :A) → (Unit → (IO :A)) → (IO :A))Run IO-OP, and run HANDLE-OP to handle exceptions of any type thrown by IO-OP.
(MAP-INTO-IO_ ITR A->MB) FUNCTION · src
∀ :A :B :C :D. (LiftIo IO :D) (IntoIterator :A :B) ⇒ (:A → (:B → (IO :C)) → (:D (List :C)))Efficiently perform a monadic operation for each element of an iterator and return the results. More efficient than map-into-io, if you can run your effect in a BaseIo.
(FOREACH-IO_ ITR A->MB) FUNCTION · src
∀ :A :B :C :D. (LiftIo IO :D) (IntoIterator :A :B) ⇒ (:A → (:B → (IO :C)) → (:D Unit))Efficiently perform a monadic operation for each element of an iterator. More efficient than foreach-io, if you can run your effect in a BaseIo.
(RERAISE-IO OP CATCH-OP) FUNCTION · src
∀ :A :B. ((IO :A) → (Unit → (IO :B)) → (IO :A))(RAISE-IO_) FUNCTION · src
∀ :A. (RuntimeRepr :A) (Signalable :A) ⇒ (:A → (IO Unit))(HANDLE-IO IO-OP HANDLE-OP) FUNCTION · src
∀ :A :B. RuntimeRepr :B ⇒ ((IO :A) → (:B → (IO :A)) → (IO :A))(RAISE-IO E) FUNCTION · src
∀ :A :B. (RuntimeRepr :A) (Signalable :A) ⇒ (:A → (IO :B))(RUN-IO! IO-OP) FUNCTION · src
∀ :A. ((IO :A) → :A)Top-level run-io! that raises any unhandled exceptions.
Package IO/RESOURCE
Types
ExitCase TYPE · src
Signals the exit condition for an effectful computation using some resource.
Instances
Eq :A ⇒ Eq (ExitCase :A)RuntimeRepr (ExitCase :A)
Values
(BRACKET-IO-MASKED_ ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :A :B :C :D :E :F. (MonadException :C) (MonadIoThread :A :B :C) ⇒ ((:C :D) → (:D → (:C :E)) → (:D → (:C :F)) → (:C :F))Acquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. Masks the thread during the entire operation, including the computation.
(BRACKET-IO-MASKED ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :A :B :C :D :E :F :G. (MonadException :C) (MonadIoThread :A :B :C) (RuntimeRepr :E) (Signalable :E) ⇒ ((:C :D) → (:D → (ExitCase :E) → (:C :F)) → (:D → (:C :G)) → (:C :G))WARNING: BRACKET-IO-MASKED will *only* cleanup if the raised exception matches :e, or if the computation succeedes. To guarantee cleanup after any exception, use BRACKET-IO-MASKED_ Acquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. Masks the thread during the entire operation, including the computation.
(BRACKET-IO_ ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :A :B :C :D :E :F. (MonadException :C) (MonadIoThread :A :B :C) ⇒ ((:C :D) → (:D → (:C :E)) → (:D → (:C :F)) → (:C :F))Acquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. Masks the thread during resource acquisition and release. The computation is not masked, but if another thread stops this one during the computation then the resource will release before the thread is stopped.
(BRACKET-IO ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :A :B :C :D :E :F :G. (MonadException :C) (MonadIoThread :A :B :C) (RuntimeRepr :E) (Signalable :E) ⇒ ((:C :D) → (:D → (ExitCase :E) → (:C :F)) → (:D → (:C :G)) → (:C :G))WARNING: BRACKET-IO will *only* cleanup if the raised exception matches :e, or if the computation succeedes. To guarantee cleanup after any exception, use BRACKET-IO_ Acquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. Masks the thread during resource acquisition and release. The computation is not masked, but if another thread stops this one during the computation then the resource will release before the thread is stopped (if :e = ThreadingException). Example of using BRACKET-IO to clean after stops: (bracket-io (pure Unit) (fn (_resource exit-case) (do-match exit-case ((Errored (InterruptCurrentThread _)) (write stopped True) (s-signal cleanup-done-gate)) (_ (s-signal cleanup-done-gate)))) (fn (_) (do (s-signal start-gate) (s-await wait-forever))))))
(WITH-MASK OP) FUNCTION · src
∀ :A :B :C :D. (MonadIoThread :A :B :C) (MonadException :C) ⇒ ((:C :D) → (:C :D))Mask the current thread while running OP, automatically unmasking afterward.
Package IO/MUT
Classes
MonadIoVar CLASS · src
Monad :A ⇒ MonadIoVar :AMethods:
NEW-VAR :: (:A → (:B (Var :A)))
Create a new variable with an initial value.READ :: ((Var :A) → (:B :A))
Read the current value stored in a variable.WRITE :: ((Var :A) → :A → (:B :A))
Set the value in a variable and return the old value.MODIFY :: ((Var :A) → (:A → :A) → (:B :A))
Modify the value in a variable by applying F, and return the old value.
Instances
MonadIoVar :A ⇒ MonadIoVar ((FreeT TermStubF) :A)MonadIoVar IOMonadIoVar :A ⇒ MonadIoVar (LoopT :A)MonadIoVar :A ⇒ MonadIoVar ((EnvT :B) :A)MonadIoVar :A ⇒ MonadIoVar ((StateT :B) :A)
Values
(MODIFY FS->S) FUNCTION · src
∀ :A. ((:A → :A) → (ST :A Unit))Modify the state in a StatefulComputation, discarding the old state.
(MODIFY ATM F) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → (:A → :A) → (:B :A))Atomically modify by applying F, then return the new value of the atomic variable. F may be called multiple times, and must be a pure function. If F errors, it will be raised in (:m :a) as an UnhandledError exception, and the atomic variable will not be modified.
(WRITE ATM VAL) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → :A → (:B Unit))Write a new value to an atomic variable.
(READ ATM) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → (:B :A))Read the value from an atomic variable.
(MODIFY HM KEY F) FUNCTION · src
∀ :A :B. Hash :A ⇒ ((HashMap :A :B) → :A → (:B → :B) → (HashMap :A :B))Modify the value at KEY with F. Returns the modified `HashMap`.
(READ ATM) FUNCTION · src
∀ :A. ((Atomic :A) → :A)Read the value of an atomic cell `atm`.
(READ ATOMIC) FUNCTION · src
(AtomicInteger → U64)Returns the current value of `atomic'.
(READ MUTEX) FUNCTION · src
∀ :A. ((Mutex :A) → :A)Access the value held in a Mutex.
(READ CEL) FUNCTION · src
∀ :A. ((Cell :A) → :A)Read the value of a mutable cell `cel`.
Package IO/TERM
Classes
MonadIoTerm CLASS · src
MonadIo :A ⇒ MonadIoTerm :AMethods:
WRITE :: Into :A String ⇒ (:A → (:B Unit))
Write a string to standard output.WRITE-LINE :: Into :A String ⇒ (:A → (:B Unit))
Write a string to standard output followed by a newline.READ-LINE :: (:A String)
Read a line from standard input.
Instances
MonadIo :A ⇒ MonadIoTerm ((FreeT TermStubF) :A)MonadIoTerm IOMonadIoTerm :A ⇒ MonadIoTerm (LoopT :A)MonadIoTerm :A ⇒ MonadIoTerm ((EnvT :B) :A)MonadIoTerm :A ⇒ MonadIoTerm ((StateT :B) :A)
Values
(WRITE ATM VAL) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → :A → (:B Unit))Write a new value to an atomic variable.
(WRITE-LINE STREAM S) FUNCTION · src
((FileStream Char) → String → (Result FileError Unit))Writes a string with an appended newline to a filestream of type Char.
(READ-LINE STREAM) FUNCTION · src
((FileStream Char) → (Result FileError String))Reads a line of characters from a FileStream.
Package IO/RANDOM
Classes
MonadIoRandom CLASS · src
Monad :A ⇒ MonadIoRandom :AMethods:
MAKE-RANDOM-STATE :: (:A RandomState)
Create a fresh random state.COPY-RANDOM-STATE :: (RandomState → (:A RandomState))
Create a copy of another random state, starting at the same seed.GET-CURRENT-RANDOM-STATE :: (:A RandomState)
Get the current thread's random state.SET-CURRENT-RANDOM-STATE :: (RandomState → (:A Unit))
Set the current thread's random state.RANDOM :: RandomLimit :A ⇒ (RandomState → :A → (:B :A))
Generate a random value less than LIMIT using the given random state.RANDOM_ :: RandomLimit :A ⇒ (:A → (:B :A))
Generate a random value less than LIMIT using the current random state.
Instances
MonadIoRandom :A ⇒ MonadIoRandom ((FreeT TermStubF) :A)MonadIoRandom IOMonadIoRandom :A ⇒ MonadIoRandom (LoopT :A)MonadIoRandom :A ⇒ MonadIoRandom ((EnvT :B) :A)MonadIoRandom :A ⇒ MonadIoRandom ((StateT :B) :A)
RandomLimit CLASS · src
Num :A ⇒ RandomLimit :AA number that can be used to bound a random number value.
Instances
Values
(RANDOM-ELT#_ LST) FUNCTION · src
∀ :A :B. MonadIoRandom :B ⇒ ((List :A) → (:B :A))Get a random element from LST. Errors if LST is empty.
(RANDOM-ELT_ LST) FUNCTION · src
∀ :A :B. MonadIoRandom :B ⇒ ((List :A) → (:B (Optional :A)))Get a random element from LST. Returns NONE if LST is empty.
(RANDOM-ELT# RS LST) FUNCTION · src
∀ :A :B. MonadIoRandom :B ⇒ (RandomState → (List :A) → (:B :A))Get a random element from LST. Errors if LST is empty.
(RANDOM-ELT RS LST) FUNCTION · src
∀ :A :B. MonadIoRandom :B ⇒ (RandomState → (List :A) → (:B (Optional :A)))Get a random element from LST. Returns NONE if LST is empty.
Package IO/THREAD
Types
UNMASKFINALLYMODE TYPE · src
When a thread unmasks and calls a cleanup operation, the thread is either: * Still running, and will cleanup and continue * Received a stop while it was masked, and will cleanup and then terminate itself.
Classes
MonadIoThread CLASS · src
(MonadIo :A) (Runtime :B :C) ⇒ MonadIoThread :B :C :AA MonadIo which can spawn :t's. Other :t's error separately. A spawned :t erroring will not cause the parent :t to fail. :t can be any 'thread-like' object, depending on the underlying implementation - system threads, software-managed green threads, etc.
Instances
MonadIoThread :A :B :C ⇒ MonadIoThread :A :B ((FreeT TermStubF) :C)MonadIoThread IoRuntime IoThread IOMonadIoThread :A :B :C ⇒ MonadIoThread :A :B (LoopT :C)MonadIoThread :A :B :C ⇒ MonadIoThread :A :B ((EnvT :D) :C)MonadIoThread :A :B :C ⇒ MonadIoThread :A :B ((StateT :D) :C)
Concurrent CLASS · src
Concurrent :A :BA Concurrent has thread-like semantics. It can be stopped, masked, unmasked, and await-ed. Concurrents don't have a uniform fork function, becasue they require different initialization input.
Methods:STOP :: (MonadException :A) (MonadIoThread :B :C :A) ⇒ (:D → (:A Unit))
Stop a Concurrent. If the Concurrent has already stopped, does nothing. If the Concurrent is masked, this will pend a stop on the Concurrent. When/if the Concurrent becomes completely unmaksed, it will stop iself. Regardless of whether the target Concurrent is masked, STOP does not block or wait for the target to complete.AWAIT :: (MonadException :A) (MonadIoThread :B :C :A) ⇒ (:D → (:A :E))
Block the current thread until the target Concurrent is completed, and retrieve its value. Re-raises if the target Concurrent raised an unhandled exceptionMASK :: (MonadException :A) (MonadIoThread :B :C :A) ⇒ (:D → (:A Unit))
Mask the Concurrent so it can't be stopped.UNMASK :: (MonadException :A) (MonadIoThread :B :C :A) ⇒ (:D → (:A Unit))
Unmask the Concurrent so it can be stopped. Unmask respects nested masks - if the Concurrent has been masked N times, it can only be stopped after being unmasked N times. When the Concurrent unmasks, if there are any pending stops, it will immediately stop itself.UNMASK-FINALLY :: (UnliftIo :A :B) (LiftTo :A :C) (MonadIoThread :D :E :A) (MonadException :C) (MonadIoThread :D :E :C) ⇒ (:F → (UNMASKFINALLYMODE → (:A :G)) → (:C Unit))
Unmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
Instances
Concurrent :A :B ⇒ Concurrent (ConcurrentGroup :A :B) (List :B)Concurrent (Future :A) :AConcurrent IoThread Unit
Runtime CLASS · src
Runtime :A :BThis class doesn't represent data, but the type tells a Concurrent and a MonadIoThread how to hook into the native threading implementations that a runtime provides. A runtime has a 'base' concurrent, which is the underlying thread/fiber/etc. that the runtime produces to run concurrently. All other Concurrents are built by composing on the base concurrent somehow. Runtime is a low-level type that operates inside the normal MonadIo layer. It should not be used by normal application code. Its two main purposes are: (1) to make MonadIoThread generic over the type of thread it forks, and (2) to build low-level, efficient concurrency tools that are generic over the underlying thread type.
Methods:CURRENT-THREAD! :: ((Proxy :A) → :B)
Get a handle for the current thread.SLEEP! :: ((Proxy :A) → UFix → Unit)
Sleep the current thread for MSECS milliseconds.FORK! :: ((Proxy :A) → (Unit → (Result Dynamic :B)) → :C)
Spawn a new thread, which starts running immediately. Returns the handle to the thread.FORK-THROW! :: ((Proxy :A) → (Unit → (Result Dynamic :B)) → :C)
Spawn a new thread, which starts running immediately. Returns the handle to the thread. If the thread raises an unhandled exception, throws immediately. The underlying system determines the result of the throw, but it could include terminating the whole program.JOIN! :: ((Proxy :A) → :B → (Result Dynamic Unit))
Block the current thread until the target thread is completed. Does not a retrieve value. Raises an exception if the target thread raised an unhandled exception, wrapping the target thread's raised exception. JOIN! is the lowest level operation to block on another thread's termination, and most code should use AWAIT instead.STOP! :: ((Proxy :A) → :B → Unit)
Stop a :t. If the thread has already stopped, does nothing. If the :t is masked, this will pend a stop on the :t. When/if the :t becomes completely unmaksed, it will stop iself. Regardless of whether the target :t is masked, STOP does not block or wait for the target thread to complete.MASK! :: ((Proxy :A) → :B → Unit)
Mask the thread so it can't be stopped.UNMASK! :: ((Proxy :A) → :B → Unit)
Unmask the thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times. When the thread unmasks, if there are any pending stops, it will immediately be stopped.UNMASK-FINALLY! :: ((Proxy :A) → :B → (UNMASKFINALLYMODE → :C) → Unit)
Unmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
Values
(AWAIT CV LOCK) FUNCTION · src
(ConditionVariable → Lock → Unit)Atomically release `lock' and enqueue the calling thread waiting for `cv'. The thread will resume when another thread has notified it using `notify-cv'; it may also resume if interrupted by some external event or in other implementation-dependent circumstances: the caller must always test on waking that there is threading to be done, instead of assuming that it can go ahead.
(UNMASK-CURRENT-THREAD-FINALLY OP-FINALLY) FUNCTION · src
∀ :A :B :C :D :E. (UnliftIo :D :A) (LiftTo :D :E) (MonadIoThread :B :C :D) ⇒ ((UNMASKFINALLYMODE → (:D Unit)) → (:E Unit))Unmask the current thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
(UNMASK-THREAD-FINALLY THREAD OP-FINALLY) FUNCTION · src
∀ :A :B :C :D :E :F. (UnliftIo :D :A) (LiftTo :D :F) (MonadIoThread :B :C :D) ⇒ (:C → (UNMASKFINALLYMODE → (:D :E)) → (:F Unit))Unmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
UNMASK-CURRENT-THREAD VALUE · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (:C Unit)Unmask the current thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times.
MASK-CURRENT-THREAD VALUE · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (:C Unit)Mask the current thread so it can't be stopped.
(FORK-THREAD-THROW OP) FUNCTION · src
∀ :A :B :C :D :E :F. (UnliftIo :C :A) (LiftTo :C :E) (MonadIoThread :B :F :C) ⇒ ((:C :D) → (:E :F))Spawn a new thread, which starts running immediately. Returns the handle to the thread. If the thread raises an unhandled exception, throws immediately. The underlying system determines the result of the throw, but it could include terminating the whole program.
(UNMASK-CURRENT! RT-PRX) FUNCTION · src
∀ :A :B. Runtime :B :A ⇒ ((Proxy :B) → Unit)Unmask the current thread.
CURRENT-THREAD VALUE · src
∀ :A :B :C. MonadIoThread :A :C :B ⇒ (:B :C)Get the current thread.
(UNMASK-THREAD THREAD) FUNCTION · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (:B → (:C Unit))Unmask the thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times.
(MASK-CURRENT! RT-PRX) FUNCTION · src
∀ :A :B. Runtime :B :A ⇒ ((Proxy :B) → Unit)Mask the current thread.
(STOP-THREAD THREAD) FUNCTION · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (:B → (:C Unit))Stop a thread. If the thread has already stopped, does nothing.
(MASK-THREAD THREAD) FUNCTION · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (:B → (:C Unit))Mask the thread so it can't be stopped.
(JOIN-THREAD THREAD) FUNCTION · src
∀ :A :B :C. (MonadIoThread :A :B :C) (MonadException :C) ⇒ (:B → (:C Unit))Block the current thread until the target thread is completed. Does not a retrieve value. Raises an exception if the target thread raised an unhandled exception, wrapping the target thread's raised exception. JOIN-THREAD is the lowest level operation to block on another thread's termination.
(FORK-THREAD OP) FUNCTION · src
∀ :A :B :C :D :E :F. (UnliftIo :C :A) (LiftTo :C :E) (MonadIoThread :B :F :C) ⇒ ((:C :D) → (:E :F))Spawn a new thread, which starts running immediately. Returns the handle to the thread. If the thread raises an unhandled exception, it will be logged to *ERROR-OUTPUT* and swallowed, until/if the thread is joined. This version can accept any underlying BaseIo, which can be useful, but causes inference issues in some cases.
(SLEEP MSEC) FUNCTION · src
∀ :A :B :C. MonadIoThread :A :B :C ⇒ (UFix → (:C Unit))Sleep the current thread for MSECS milliseconds.
(AWAIT SEM) FUNCTION · src
(Semaphore → Unit)Decrement the count of `sem' by 1 if the count is larger than zero. If the count is zero, blocks until `sem' can be decremented.
(AWAIT BARRIER) FUNCTION · src
(Barrier → Unit)(CURRENT-THREAD _) FUNCTION · src
(Unit → LispThread)Returns the thread object representing the calling thread.
(SLEEP N) FUNCTION · src
∀ :A. Rational :A ⇒ (:A → Unit)Sleep for `n` seconds, where `n` can be of any type with an instance of `Rational`. Sleep uses type class `Rational`'s `best-approx` instead of `Real`'s `real-approx` because it handles the approximation without arbitrary precision. The only `Real` type excluded by this decision is `CReal`.
(WRITE-LINE-SYNC MSG) FUNCTION · src
∀ :A :B. (Into :A String) (MonadIoTerm :B) ⇒ (:A → (:B Unit))Perform a synchrozied write-line to the terminal. Not performant - mainly useful for debugging.
(UNMASK-THREAD-FINALLY_) FUNCTION · src
∀ :A :B. (LiftTo IO :B) (MonadException :B) (MonadIoThread IoRuntime IoThread :B) ⇒ (IoThread → (UNMASKFINALLYMODE → (IO :A)) → (:B Unit))(FORK-THREAD-THROW_) FUNCTION · src
∀ :A :B. (MonadIoThread IoRuntime IoThread :B) (LiftTo IO :B) ⇒ ((IO :A) → (:B IoThread))(UNMASK-FINALLY_) FUNCTION · src
∀ :A :B :C :D. (LiftTo IO :D) (MonadException :D) (Concurrent :B :A) (MonadIoThread IoRuntime IoThread :D) ⇒ (:B → (UNMASKFINALLYMODE → (IO :C)) → (:D Unit))(FORK-THREAD_) FUNCTION · src
∀ :A :B. (MonadIoThread IoRuntime IoThread :B) (LiftTo IO :B) ⇒ ((IO :A) → (:B IoThread))Package IO/FILE
Classes
MonadIoFile CLASS · src
MonadIo :A ⇒ MonadIoFile :AMethods:
EXISTS? :: Into :A Pathname ⇒ (:A → (:B (Result FileError Boolean)))
Returns whether a file or directory exists.FILE-EXISTS? :: Into :A Pathname ⇒ (:A → (:B (Result FileError Boolean)))
Returns True if a pathname names a file that exists.DIRECTORY-EXISTS? :: Into :A Pathname ⇒ (:A → (:B (Result FileError Boolean)))
Returns True if a pathname names a directory that exists.OPEN :: File :A ⇒ (StreamOptions → (:B (Result FileError (FileStream :A))))CLOSE :: ((FileStream :A) → (:B (Result FileError :C)))
Closes a FileStream.ABORT :: ((FileStream :A) → (:B (Result FileError :C)))
Closes a FileStream and aborts all operations..CREATE-TEMP-DIRECTORY :: (:A (Result FileError Pathname))CREATE-TEMP-FILE :: (String → (:A (Result FileError Pathname)))COPY :: (Into :A Pathname) (Into :B Pathname) ⇒ (:A → :B → (:C (Result FileError Unit)))
Copies a file to a new location.CREATE-DIRECTORY :: Into :A Pathname ⇒ (:A → (:B (Result FileError Pathname)))
This is equivalent to `mkdir -p`. Creates a directory and its parents. The pathname must be a valid directory pathname.DELETE-FILE :: Into :A Pathname ⇒ (:A → (:B (Result FileError Unit)))
Deletes a given file if the file exists.REMOVE-DIRECTORY :: Into :A Pathname ⇒ (:A → (:B (Result FileError :A)))
Deletes an empty directory.REMOVE-DIRECTORY-RECURSIVE :: Into :A Pathname ⇒ (:A → (:B (Result FileError Unit)))
Deletes a target directory recursively. Equivalent to `rm -r`. Errors if the path is not a directory.SYSTEM-RELATIVE-PATHNAME :: Into :A String ⇒ (:A → String → (:B (Result FileError Pathname)))
Generates a system-relative-pathname for a given filename or path. This is a wrapper for `asdf:system-relative-pathname`. `Name` will likely be an empty string unless a subdirectory or filename is specified.READ-FILE-TO-STRING :: Into :A Pathname ⇒ (:A → (:B (Result FileError String)))
Reads a file into a string, given a pathname string.READ-FILE-LINES :: Into :A Pathname ⇒ (:A → (:B (Result FileError (List String))))
Reads a file into lines, given a pathname or string.READ-CHAR :: ((FileStream Char) → (:A (Result FileError Char)))
Reads a character from an FileStream.READ-LINE :: ((FileStream Char) → (:A (Result FileError String)))WRITE-CHAR :: ((FileStream Char) → Char → (:A (Result FileError Unit)))
Writes a `Char` to the stream.WRITE-LINE :: ((FileStream Char) → String → (:A (Result FileError Unit)))
Writes a string with an appended newline to a filestream of type Char.WRITE-STRING :: ((FileStream Char) → String → (:A (Result FileError Unit)))
Writes a `string` to a FileStream of type Char.READ-FILE-TO-VECTOR :: File :A ⇒ ((FileStream :A) → (:B (Result FileError (Vector :A))))
Reads a file into a vector of type `:a`.READ-VECTOR :: File :A ⇒ ((FileStream :A) → UFix → (:B (Result FileError (Vector :A))))
Reads a chunk of a file into a vector of type `:a`.WRITE-VECTOR :: (File :A) (RuntimeRepr :A) ⇒ ((FileStream :A) → (Vector :A) → (:B (Result FileError Unit)))
Writes elements of an vector of type `:a` to a stream of type `:a`.WRITE-TO-FILE :: (Into :A Pathname) (File :B) (RuntimeRepr :B) ⇒ (:A → (Vector :B) → (:C (Result FileError Unit)))
Opens and writes to a file with data of type :a. Supersedes existing data on the file.APPEND-TO-FILE :: (Into :A Pathname) (File :B) (RuntimeRepr :B) ⇒ (:A → (Vector :B) → (:C (Result FileError Unit)))
Opens and appends a file with data of type :a.SET-FILE-POSITION :: ((FileStream :A) → UFix → (:B (Result FileError Unit)))
Sets the file position of a file stream.
Instances
MonadIoFile :A ⇒ MonadIoFile ((FreeT TermStubF) :A)MonadIoFile IOMonadIoFile :A ⇒ MonadIoFile (LoopT :A)MonadIoFile :A ⇒ MonadIoFile ((EnvT :B) :A)MonadIoFile :A ⇒ MonadIoFile ((StateT :B) :A)
Values
(COPY V) FUNCTION · src
∀ :A. ((LispArray :A) → (LispArray :A))Make a deep copy of the `LispArray` `v`.
(COPY V) FUNCTION · src
∀ :A. ((Vector :A) → (Vector :A))Return a new vector containing the same elements as `v`.
(COPY Q) FUNCTION · src
∀ :A. ((Queue :A) → (Queue :A))Return a new queue containing the same elements as `q`.
(SYSTEM-RELATIVE-PATHNAME SYSTEM-NAME NAME) FUNCTION · src
∀ :A. Into :A String ⇒ (:A → String → (Result FileError Pathname))Generates a system-relative-pathname for a given filename or path. This is a wrapper for `asdf:system-relative-pathname`. `Name` will likely be an empty string unless a subdirectory or filename is specified.
(WITH-TEMP-DIRECTORY THUNK) FUNCTION · src
∀ :A. ((Pathname → (Result FileError :A)) → (Result FileError :A))Performs an operation `thunk` inside a temporary directory.
(READ-FILE-TO-VECTOR STREAM) FUNCTION · src
∀ :A. File :A ⇒ ((FileStream :A) → (Result FileError (Vector :A)))Reads a file into a vector of type `:a`.
(READ-FILE-TO-STRING PATH) FUNCTION · src
∀ :A. Into :A Pathname ⇒ (:A → (Result FileError String))Reads a file into a string, given a pathname string.
(SET-FILE-POSITION STREAM I) FUNCTION · src
∀ :A. ((FileStream :A) → UFix → (Result FileError Unit))Sets the file position of a file stream.
(DIRECTORY-EXISTS? PATH) FUNCTION · src
∀ :A. Into :A Pathname ⇒ (:A → (Result FileError Boolean))Returns True if a pathname names a directory that exists.
(READ-FILE-LINES PATH) FUNCTION · src
∀ :A. Into :A Pathname ⇒ (:A → (Result FileError (List String)))Reads a file into lines, given a pathname or string.
(WITH-TEMP-FILE FILE-TYPE THUNK) FUNCTION · src
∀ :A :B. File :A ⇒ (String → ((FileStream :A) → (Result FileError :B)) → (Result FileError :B))Performs an operation `thunk` on a temporary file. File type extensions need to include `.`, like ".txt".
(WITH-OPEN-FILE STREAM-OPTIONS THUNK) FUNCTION · src
∀ :A :B. File :A ⇒ (StreamOptions → ((FileStream :A) → (Result FileError :B)) → (Result FileError :B))Opens a file stream, performs `thunk` on it, then closes the stream.
(WRITE-VECTOR STREAM V) FUNCTION · src
∀ :A. (RuntimeRepr :A) (File :A) ⇒ ((FileStream :A) → (Vector :A) → (Result FileError Unit))Writes elements of an vector of type `:a` to a stream of type `:a`.
(WRITE-STRING FS S) FUNCTION · src
((FileStream Char) → String → (Result FileError Unit))Writes a `string` to a FileStream of type Char.
(FILE-EXISTS? PATH) FUNCTION · src
∀ :A. Into :A Pathname ⇒ (:A → (Result FileError Boolean))Returns True if a pathname names a file that exists.
(READ-VECTOR STREAM CHUNK-SIZE) FUNCTION · src
∀ :A. File :A ⇒ ((FileStream :A) → UFix → (Result FileError (Vector :A)))Reads a chunk of a file into a vector of type `:a`.
(WRITE-LINE STREAM S) FUNCTION · src
((FileStream Char) → String → (Result FileError Unit))Writes a string with an appended newline to a filestream of type Char.
(WRITE-CHAR STREAM DATA) FUNCTION · src
((FileStream Char) → Char → (Result FileError Unit))Writes a `Char` to the stream.
(READ-LINE STREAM) FUNCTION · src
((FileStream Char) → (Result FileError String))Reads a line of characters from a FileStream.
(READ-CHAR STREAM) FUNCTION · src
((FileStream Char) → (Result FileError Char))Reads a character from an FileStream.
(EXISTS? PATH) FUNCTION · src
∀ :A. Into :A Pathname ⇒ (:A → (Result FileError Boolean))Returns whether a file or directory exists.
(CLOSE STREAM) FUNCTION · src
∀ :A :B. ((FileStream :A) → (Result FileError :B))Closes a FileStream.
(ABORT STREAM) FUNCTION · src
∀ :A :B. ((FileStream :A) → (Result FileError :B))Closes a FileStream and aborts all operations..
(COPY SEQ) FUNCTION · src
∀ :A. ((Seq :A) → (Seq :A))A shallow copy of `seq`
(WITH-TEMP-DIRECTORY K) FUNCTION · src
∀ :A :B :C :D :E :F. (LiftTo :D :F) (UnliftIo :D :A) (LiftIo :A :A) (MonadIoThread :B :C :A) (MonadException :A) (MonadIoFile :A) ⇒ ((Pathname → (:D :E)) → (:F :E))Performs an operation `thunk` inside a temporary directory. Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-TEMP-DIRECTORY_ if you have issues.
(WITH-TEMP-FILE FILE-TYPE K) FUNCTION · src
∀ :A :B :C :D :E :F :G. (LiftTo :E :G) (UnliftIo :E :A) (LiftIo :A :A) (MonadIoThread :B :C :A) (File :D) (MonadException :A) (MonadIoFile :A) ⇒ (String → ((FileStream :D) → (:E :F)) → (:G :F))Performs an operation `thunk` on a temporary file. File type extensions need to include `.` Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-TEMP-FILE_ if you have issues.
(WITH-OPEN-FILE OPTS K) FUNCTION · src
∀ :A :B :C :D :E :F :G. (LiftTo :E :G) (UnliftIo :E :A) (LiftIo :A :A) (MonadIoThread :B :C :A) (File :D) (MonadException :A) (MonadIoFile :A) ⇒ (StreamOptions → ((FileStream :D) → (:E :F)) → (:G :F))Opens a file stream, performs K on it, then closes the stream. Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-OPEN-FILE_ if you have issues.
(WITH-TEMP-DIRECTORY_) FUNCTION · src
∀ :A :B. (UnliftIo :B IO) (LiftTo IO :B) ⇒ ((Pathname → (IO :A)) → (:B :A))(WITH-TEMP-FILE_) FUNCTION · src
∀ :A :B :C. (File :A) (UnliftIo :C IO) (LiftTo IO :C) ⇒ (String → ((FileStream :A) → (IO :B)) → (:C :B))(WITH-OPEN-FILE_) FUNCTION · src
∀ :A :B :C. (File :A) (UnliftIo :C IO) (LiftTo IO :C) ⇒ (StreamOptions → ((FileStream :A) → (IO :B)) → (:C :B))Package IO/UNIQUE
Classes
MonadIoUnique CLASS · src
Monad :A ⇒ MonadIoUnique :AMethods:
NEW-UNIQUE :: (:A Unique)
Generate a value that will be unique within this run of the program. Threadsafe - calling from different threads will still result in unique values across all threads.
Instances
MonadIoUnique :A ⇒ MonadIoUnique ((FreeT TermStubF) :A)MonadIoUnique :A ⇒ MonadIoUnique (LoopT :A)MonadIoUnique :A ⇒ MonadIoUnique ((EnvT :B) :A)MonadIoUnique :A ⇒ MonadIoUnique ((StateT :B) :A)
Values
(TO-INT (UNIQUE% I)) FUNCTION · src
(Unique → Integer)Convert a unique value to an integer. It is guaranteed that: (/= (to-int a) (to-int b)) for any two different Unique instances.
Package IO/STM
Types
TVar TYPE · src
STM TYPE · src
Instances
(MonadException :A) (MonadIo :A) ⇒ MonadException (STM :A)Functor :A ⇒ Functor (STM :A)Monad :A ⇒ Applicative (STM :A)Monad :A ⇒ Monad (STM :A)RuntimeRepr ((STM :A) :B)
Classes
MonadIoSTM CLASS · src
MonadIo :A ⇒ MonadIoSTM :AA MonadIo which can execute atomic transactions. The critical section of transaction commits is masked, so stopping a thread during a transaction won't leave the STM in an inoperable state. Read-only transactions never mask. Transactions are only masked during the brief commit period; the thread is still stoppable during the bulk of the transaction unless you mask it yourself.
Methods:NEW-TVAR :: (:A → (:B (TVar :A)))
Create a new mutable variable that can be used inside an atomic transaction.READ-TVAR :: ((TVar :A) → ((STM :B) :A))
Read a mutable variable inside an atomic transaction.WRITE-TVAR :: ((TVar :A) → :A → ((STM :B) Unit))
Write to a mutable variable inside an atomic transaction.MODIFY-TVAR :: ((TVar :A) → (:A → :A) → ((STM :B) :A))
Modify a mutable variable inside an atomic transaction.RETRY :: ((STM :A) :B)
Retry the current operation because the observed state is invalid.OR-ELSE :: (((STM :A) :B) → ((STM :A) :B) → ((STM :A) :B))
Run TX-A. If it signals a retry, run TX-b. If both transactions signal a retry, then the entire transaction retries.RUN-TX :: (((STM :A) :B) → (:A :B))
Run an atomic transaction. If the transaction raises an exception, the transaction is aborted and the exception is re-raised.
Instances
MonadIoSTM IOMonadIoSTM :A ⇒ MonadIoSTM (LoopT :A)MonadIoSTM :A ⇒ MonadIoSTM ((EnvT :B) :A)MonadIoSTM :A ⇒ MonadIoSTM ((StateT :B) :A)
Package IO/CONC/FUTURE
Values
(TRY-READ-FUTURE FUTURE) FUNCTION · src
∀ :A :B :C :D. (MonadIoThread :A :B :D) (MonadException :D) ⇒ ((Future :C) → (:D (Optional :C)))Try to read the current value from FUTURE, returning NONE if it is not available. Raises any exceptions in the awaiting thread that were raised in the future thread.
(FORK-FUTURE TASK) FUNCTION · src
∀ :A :B :C :D :E :F. (MonadException :D) (LiftTo :D :F) (UnliftIo :D :A) (MonadIoThread :B :C :D) (MonadIoThread :B :C :F) ⇒ ((:D :E) → (:F (Future :E)))Spawn a new future, which will run and eventually return the result from TASK. The future is guaranteed to only ever run at most once, when the produced :m is run.
(FORK-FUTURE_) FUNCTION · src
∀ :A :B. (MonadIoThread IoRuntime IoThread :B) (LiftTo IO :B) ⇒ ((IO :A) → (:B (Future :A)))Spawn a new future, which will run and eventually return the result from TASK. The future is guaranteed to only ever run at most once, when the produced :m is run.
Package IO/CONC/ATOMIC
Values
(MODIFY-SWAP FS->S) FUNCTION · src
∀ :A. ((:A → :A) → (ST :A :A))Modify the state in a StatefulComputation, returning the old state.
(MODIFY FS->S) FUNCTION · src
∀ :A. ((:A → :A) → (ST :A Unit))Modify the state in a StatefulComputation, discarding the old state.
(MODIFY-SWAP ATM F) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → (:A → :A) → (:B :A))Atomically modify by applying F, then return the old value of the variable. F may be called multiple times, and must be a pure function. If F errors, it will be raised in (:m :a) as an UnhandledError exception, and the atomic variable will not be modified.
(NEW-AT-VAR VAL) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ (:A → (:B (AtVar :A)))Create a new atomic variable with an initial value.
(MODIFY ATM F) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → (:A → :A) → (:B :A))Atomically modify by applying F, then return the new value of the atomic variable. F may be called multiple times, and must be a pure function. If F errors, it will be raised in (:m :a) as an UnhandledError exception, and the atomic variable will not be modified.
(WRITE ATM VAL) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → :A → (:B Unit))Write a new value to an atomic variable.
(READ ATM) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar :A) → (:B :A))Read the value from an atomic variable.
(PUSH ATM ELT) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar (List :A)) → :A → (:B (List :A)))Atomically push a value onto an atomic list.
(POP ATM) FUNCTION · src
∀ :A :B. MonadIo :B ⇒ ((AtVar (List :A)) → (:B (Optional :A)))Atomically pop and retrieve the head of an atomic list.
(MODIFY HM KEY F) FUNCTION · src
∀ :A :B. Hash :A ⇒ ((HashMap :A :B) → :A → (:B → :B) → (HashMap :A :B))Modify the value at KEY with F. Returns the modified `HashMap`.
(READ ATM) FUNCTION · src
∀ :A. ((Atomic :A) → :A)Read the value of an atomic cell `atm`.
(READ ATOMIC) FUNCTION · src
(AtomicInteger → U64)Returns the current value of `atomic'.
(READ MUTEX) FUNCTION · src
∀ :A. ((Mutex :A) → :A)Access the value held in a Mutex.
(READ CEL) FUNCTION · src
∀ :A. ((Cell :A) → :A)Read the value of a mutable cell `cel`.
(PUSH SEQ A) FUNCTION · src
∀ :A. ((Seq :A) → :A → (Seq :A))Push `a` onto the end of `seq`, returning a new `Seq` instance.
(POP SEQ) FUNCTION · src
∀ :A. ((Seq :A) → (Optional (Tuple :A (Seq :A))))If `seq` is empty, return `None`. Otherwise, the last member of `seq` and a new `Seq` instance.
Package IO/CONC/MVAR
Structs
MVar :A STRUCT · src
A synchronized container that can be empty or hold one :a. Can put data into the container, blocking until it is empty. Can take data out of the container, blocking until it is full. All critical MVar operations are masked, so stopping a thread that's operating on MVar's won't leave MVar's in an inoperable state. However, irresponsible stopping could still cause deadlocks, race conditions, etc. if other threads were depending on the stopped thread operating on an MVar to continue.
Instances
RuntimeRepr (MVar :A)
Values
NEW-EMPTY-MVAR VALUE · src
∀ :A :B :C :D. MonadIoThread :A :B :C ⇒ (:C (MVar :D))Create a new empty MVar.
NEW-EMPTY-CHAN VALUE · src
∀ :A :B :C :D. MonadIoThread :A :B :C ⇒ (:C (MChan :D))Create a new empty channel.
(TRY-TAKE-MVAR MVAR) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → (:D (Optional :C)))Attempt to take a value from an MVar; returns None if empty.
(TRY-READ-MVAR MVAR) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → (:D (Optional :C)))Attempt to read (without removing) the value from an MVar; returns None if empty.
(IS-EMPTY-MVAR MVAR) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → (:D Boolean))Return True if the MVar is currently empty.
(TRY-PUT-MVAR MVAR VAL) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → :C → (:D Boolean))Attempt to put a value into an MVar; returns False if full and the put fails, True if the put succeeds.
(WITH-MVAR MVAR OP) FUNCTION · src
∀ :A :B :C :D :E :F :G. (LiftTo :E :G) (UnliftIo :E :A) (MonadException :A) (MonadIoThread :B :C :A) ⇒ ((MVar :D) → (:D → (:E :F)) → (:G :F))Modify with the result of an operation. Blocks until MVar is full. If the operation raises an exception, will restore the MVar value and re-raise. If other threads are calling PUT-MVAR while the operation is running, they can block this thread until another thread takes the MVar.
(TAKE-MVAR MVAR) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → (:D :C))Take a value from an MVar, blocking until one is available.
(SWAP-MVAR MVAR NEW-VAL) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → :C → (:D :C))Atomically replace the value in an MVar and return the old value.
(READ-MVAR MVAR) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → (:D :C))Read (without removing) the value from an MVar, blocking until one is available.
(PUSH-CHAN CHAN VAL) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MChan :C) → :C → (:D Unit))Push VAL onto CHAN.
(PUT-MVAR MVAR VAL) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MVar :C) → :C → (:D Unit))Put a value into an MVar, blocking until it becomes empty.
(POP-CHAN CHAN) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ ((MChan :C) → (:D :C))Pop the front value in CHAN. Blocks while CHAN is empty.
(NEW-MVAR VAL) FUNCTION · src
∀ :A :B :C :D. MonadIoThread :A :B :D ⇒ (:C → (:D (MVar :C)))Create a new MVar containing VAL.
(WITH-MVAR_ MVAR OP) FUNCTION · src
∀ :A :B :C. (MonadIoThread IoRuntime IoThread :C) (LiftTo IO :C) ⇒ ((MVar :A) → (:A → (IO :B)) → (:C :B))Package IO/CONC/GROUP
Structs
ConcurrentGroup :A :B STRUCT · src
Handles masking, stopping, and awaiting a group of Concurrents as a unit. ConcurrentGroup does not pass messages/data. For more structured uses, see ConcurrentPool. ConcurrentGroup provides the following guarantees: * Masking/unmasking the group is atomic. If another thread attempts to stop the group, it will either stop all of the Concurrents or none of them. * When you stop the group, it will send the stop signal to all of the enclosed Concurrents. * When you await the group, it will block until all of the enclosed Concurrents have completed. * When you await the group, it will error if any one of the enclosed Concurrents errored. * Calling unmask-finally on the group runs the callback on each Concurrent separately, not once on the thread calling (unmask-finally). ConcurrentGroups guarantees are only valid if management of the enclosed Concurrents is done through the group. For example, if one thread tries to mask the group while another thread tries to stop one of the individual Concurrents in the group, then the second thread might stop the individual Concurrent before the first thread has a chance to mask it.
Instances
Concurrent :A :B ⇒ Concurrent (ConcurrentGroup :A :B) (List :B)RuntimeRepr (ConcurrentGroup :A :B)
Values
(ENCLOSE-GROUP CONCURRENTS) FUNCTION · src
∀ :A :B :C :D :E. (MonadIoThread :A :B :D) (Concurrent :C :E) ⇒ ((List :C) → (:D (ConcurrentGroup :C :E)))Enclose already forked Concurrents in a ConcurrentGroup. Warning: After calling, the enclosed Concurrents should only be managed through the group.
(FORK-GROUP FORK-CONCURRENTS) FUNCTION · src
∀ :A :B :C :D :E. (MonadIoThread :A :B :C) (Concurrent :D :E) ⇒ ((List (:C :D)) → (:C (ConcurrentGroup :D :E)))Run a list of IO operations that each forks a Concurrent. Enclose the forked Concurrents in a ConcurrentGroup.
Package IO/IO-ALL
Package IO/STUBS/TERM
Values
(RUN-TERM-STUBM OPM READ-LINE-INPUTS) FUNCTION · src
∀ :A :B. Monad :A ⇒ ((((FreeT TermStubF) :A) :B) → (List String) → (:A (Tuple (List String) :B)))(RUN-TERM-STUB STUB-OP READ-LINE-INPUTS) FUNCTION · src
∀ :A. ((((FreeT TermStubF) Identity) :A) → (List String) → (Tuple (List String) :A))