org.positronicnet.notifications
Perform the action
, usually on a worker thread associated with this
notifier.
Perform the action
, usually on a worker thread associated with this
notifier. Results may be posted back to the calling thread, viz.
the conventions documented in org.positronicnet.notifications.Actions.
Synchronously fetch the value being monitored by this Notifier
.
Synchronously fetch the value being monitored by this Notifier
.
Perform the action
, synchronously on the calling thread.
Perform the action
, synchronously on the calling thread.
Basic trait for actor-like objects which manage state of type
T
. Actors ordinarily operate on a thread associated with the state they manage (e.g., the worker thread associated with a Database). Code running on other threads usually communicates with them by sendingaction
s using an actor-likenotifier ! action
style.The base
Notifier
trait specifies a set of actions for querying the state, and requesting updates when it changes. Subclasses (e.g., RecordManager) typically support other actions which request changes to happen (which may, in turn, cause watchers to be notified).The primary reason for doing things in an actor-style syntax in Android is to deal with the fairly stringent best-practice requirements for Android "user interface threads" --- specifically, the requirement that they shouldn't be waiting for anything else, even local disk I/O (let alone, say, a network operation). So, all that stuff needs to happen on background threads; we use actor style to help keep the concurrency manageable.
However, there are also circumstances where concurrency is a nuisance. For instance, an Android
Service
orBroadcastReceiver
may want to be sure that an operation has completed before signalling that it has finished itself.For these situations, you can also request that an action be performed
onThisThread
, as innotifier.onThisThread( Fetch{ value => ... } )
which performs the
Fetch
and runs the body on the current thread, forgoing all concurrency. (Though for this particular case, there's a special-casefetchOnThisThread
method which simply fetches the monitored state and returns it as the value.)See org.positronicnet.notifications.Actions for definitions of the common action types.