cats.effect.concurrent
package cats.effect.concurrent
Type members
Classlikes
A purely functional synchronization primitive which represents a single value
which may not yet be available.
which may not yet be available.
When created, a
and never be made empty again.
Deferred
is empty. It can then be completed exactly once,and never be made empty again.
get
on an empty Deferred
will block until the Deferred
is completed.get
on a completed Deferred
will always immediately return its content.complete(a)
on an empty Deferred
will set it to a
, and notify any andall readers currently blocked on a call to
get
.complete(a)
on a Deferred
that has already been completed will not modifyits content, and result in a failed
F
.Albeit simple,
complex concurrent behaviour and data structures like queues and semaphores.
Deferred
can be used in conjunction with Ref to buildcomplex concurrent behaviour and data structures like queues and semaphores.
Finally, the blocking mentioned above is semantic only, no actual threads are
blocked by the implementation.
blocked by the implementation.
- Companion
- object
@deprecated("`MVar` is now deprecated in favour of a new generation `MVar2` with `tryRead` and `swap` support", "2.2.0")
A mutable location, that is either empty or contains a value of type
A
.It has the following fundamental atomic operations:
-
put which fills the var if empty, or blocks
(asynchronously) until the var is empty again -
tryPut which fills the var if empty. returns true if successful
-
take which empties the var if full, returning the contained
value, or blocks (asynchronously) otherwise until there is
a value to pull -
tryTake empties if full, returns None if empty.
-
read which reads the current value without touching it,
assuming there is one, or otherwise it waits until a value
is made available viaput
-
tryRead
returns a variable if it exists. Implemented in the successor MVar2 -
swap
takes a value, replaces it and returns the taken value. Implemented in the successor MVar2 -
isEmpty returns true if currently empty
The
primitives and performing simple inter-thread communications.
If it helps, it's similar with a
except that it doesn't block any threads, all waiting being
done asynchronously (via Async or Concurrent data types,
such as IO).
MVar
is appropriate for building synchronizationprimitives and performing simple inter-thread communications.
If it helps, it's similar with a
BlockingQueue(capacity = 1)
,except that it doesn't block any threads, all waiting being
done asynchronously (via Async or Concurrent data types,
such as IO).
Given its asynchronous, non-blocking nature, it can be used on
top of Javascript as well.
top of Javascript as well.
Inspired by
by
Control.Concurrent.MVar
from Haskell andby
scalaz.concurrent.MVar
.- Companion
- object
@silent("deprecated")
A mutable location, that is either empty or contains a value of type
A
.It has the following fundamental atomic operations:
-
put which fills the var if empty, or blocks
(asynchronously) until the var is empty again -
tryPut which fills the var if empty. returns true if successful
-
take which empties the var if full, returning the contained
value, or blocks (asynchronously) otherwise until there is
a value to pull -
tryTake empties if full, returns None if empty.
-
read which reads the current value without touching it,
assuming there is one, or otherwise it waits until a value
is made available viaput
-
tryRead
returns a variable if it exists. Implemented in the successor MVar2 -
swap
takes a value, replaces it and returns the taken value. Implemented in the successor MVar2 -
isEmpty returns true if currently empty
The
primitives and performing simple inter-thread communications.
If it helps, it's similar with a
except that it doesn't block any threads, all waiting being
done asynchronously (via Async or Concurrent data types,
such as IO).
MVar
is appropriate for building synchronizationprimitives and performing simple inter-thread communications.
If it helps, it's similar with a
BlockingQueue(capacity = 1)
,except that it doesn't block any threads, all waiting being
done asynchronously (via Async or Concurrent data types,
such as IO).
Given its asynchronous, non-blocking nature, it can be used on
top of Javascript as well.
top of Javascript as well.
Inspired by
by
Control.Concurrent.MVar
from Haskell andby
scalaz.concurrent.MVar
.An asynchronous, concurrent mutable reference.
Provides safe concurrent access and modification of its content, but no
functionality for synchronisation, which is instead handled by Deferred.
For this reason, a
functionality for synchronisation, which is instead handled by Deferred.
For this reason, a
Ref
is always initialised to a value.The default implementation is nonblocking and lightweight, consisting essentially
of a purely functional wrapper over an
of a purely functional wrapper over an
AtomicReference
.- Companion
- object
A purely functional semaphore.
A semaphore has a non-negative number of permits available. Acquiring a permit
decrements the current number of permits and releasing a permit increases
the current number of permits. An acquire that occurs when there are no
permits available results in semantic blocking until a permit becomes available.
decrements the current number of permits and releasing a permit increases
the current number of permits. An acquire that occurs when there are no
permits available results in semantic blocking until a permit becomes available.
Blocking acquires are cancelable if the semaphore is created with
(and hence, with a
if the semaphore is created with
Semaphore.apply
(and hence, with a
Concurrent[F]
instance). Blocking acquires are non-cancelableif the semaphore is created with
Semaphore.async
(and hence, with an Async[F]
instance).- Companion
- object