Source

gears.async.Async.Source
See theSource companion object
trait Source[+T]

An asynchronous data source. Sources can be persistent or ephemeral. A persistent source will always pass same data to calls of Source!.poll and Source!.onComplete. An ephemeral source can pass new data in every call.

Attributes

See also

An example of a persistent source is gears.async.Future.

An example of an ephemeral source is gears.async.Channel.

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class OriginalSource[T]
trait Future[T]
trait Promise[T]
class Semaphore

Members list

Value members

Abstract methods

def dropListener(k: Listener[T]): Unit

Signal that listener k is dead (i.e. will always fail to acquire locks from now on), and should be removed from onComplete queues.

Signal that listener k is dead (i.e. will always fail to acquire locks from now on), and should be removed from onComplete queues.

This permits original, (i.e. non-derived) sources like futures or channels to drop the listener from their waiting sets.

Attributes

def onComplete(k: Listener[T]): Unit

Once data is available, pass it to the listener k. onComplete is always non-blocking.

Once data is available, pass it to the listener k. onComplete is always non-blocking.

Note that k's methods will be executed on the same thread as the Source, usually in sequence. It is hence important that the listener itself does not perform expensive operations.

Attributes

def poll(k: Listener[T]): Boolean

Checks whether data is available at present and pass it to k if so. Calls to poll are always synchronous and non-blocking.

Checks whether data is available at present and pass it to k if so. Calls to poll are always synchronous and non-blocking.

The process is as follows:

  • If no data is immediately available, return false immediately.
  • If there is data available, attempt to lock k.
    • If k is no longer available, true is returned to signal this source's general availability.
    • If locking k succeeds:
      • If data is still available, complete k and return true.
      • Otherwise, unlock k and return false.

Note that in all cases, a return value of false indicates that k should be put into onComplete to receive data in a later point in time.

Attributes

Returns

Whether poll was able to pass data to k. Note that this is regardless of k being available to receive the data. In most cases, one should pass k into Source!.onComplete if poll returns false.

Concrete methods

inline def await(using Async): T
Extension method from Async

Waits for an item to arrive from the source, then automatically unwraps it. Suspends until an item returns.

Waits for an item to arrive from the source, then automatically unwraps it. Suspends until an item returns.

Attributes

See also

awaitResult for non-unwrapping await.

inline def await(using Async): T
Extension method from Async

Waits for an item to arrive from the source, then automatically unwraps it. Suspends until an item returns.

Waits for an item to arrive from the source, then automatically unwraps it. Suspends until an item returns.

Attributes

See also

awaitResult for non-unwrapping await.

final def awaitResult(using ac: Async): T

Waits for an item to arrive from the source. Suspends until an item returns.

Waits for an item to arrive from the source. Suspends until an item returns.

This is an utility method for direct waiting with Async, instead of going through listeners.

Attributes

inline def handle[U](f: T => U): SelectCase[U]
Extension method from Async

Attach a handler to src, creating a SelectCase.

Attach a handler to src, creating a SelectCase.

Attributes

See also

Async.select where SelectCase is used.

def poll(): Option[T]

Similar to poll, but instead of passing in a listener, directly return the value T if it is available.

Similar to poll, but instead of passing in a listener, directly return the value T if it is available.

Attributes

def transformValuesWith[U](f: T => U): Source[U]
Extension method from Async

Create a new source that requires the original source to run the given transformation function on every value received.

Create a new source that requires the original source to run the given transformation function on every value received.

Note that f is always run on the computation that produces the values from the original source, so this is very likely to run sequentially and be a performance bottleneck.

Value parameters

f

the transformation function to be run on every value. f is run before the item is passed to the Listener.

Attributes

inline def ~~>[U](f: T => U): SelectCase[U]
Extension method from Async

Alias for handle

Alias for handle

Attributes

See also

Async.select where SelectCase is used.