Event.Control

trait Control

Source
__.scala
class java.lang.Object
trait scala.Matchable
class Any
class Event.Control.X.Basic[Event.Control.X.Basic.A]

Def

def cancel: Boolean

Cancel the event

Cancel the event

Returns true if cancelation is a success, false if the event was already cancelled before.

Source
__.scala
def cancelIf(b: () => Boolean): Event.Control

Conditionally cancel

Conditionally cancel

Adds check to conditionally cancell the event. It will be evaluated at least before each event execution.

Source
__.scala
def cancelIfFalse(b: => Boolean): Event.Control

Conditionally cancel

Conditionally cancel

Adds check to conditionally cancell the event. It will be evaluated at least before each event execution.

Source
__.scala
def cancelIfTrue(b: => Boolean): Event.Control

Conditionally cancel

Conditionally cancel

Adds check to conditionally cancell the event. It will be evaluated at least before each event execution.

Source
__.scala

Cancel in given time

Cancel in given time

Adds check to conditionally cancell the event when given time length passes.

Source
__.scala
def isCancelled: Boolean

Cancel check

Cancel check

Returns false if the event is active

Source
__.scala
def limitRunsTo(maxRunCount: Int): Event.Control

Cancel after given execution count.

Cancel after given execution count.

Source
__.scala
def onCancel[U](b: () => U): Event.Control

On cancel event

On cancel event

Adds function to execute when the event is cancelled

Source
__.scala
def onCancelRun[U](f: => U): Event.Control

On cancel event

On cancel event

Adds code to execute when the event is cancelled

Source
__.scala
def removeHardReference: AnyRef

Make event weak referenced

Make event weak referenced

Event processing logic (usually wrapped in a function) may reference other objects, which cannot be garbage collected while the event exists.

This method wraps the controlled event into a WeakReference, so the event itself and all the contained objects may be garbage collected. When the event is garbage collected it is effectively cancelled.

The returned object is the only hard refference to the event and the program can decide when to discard it.

val idx = Idx.OM[Int]()

var hardRef = idx.onChange(_.stream.print).removeHardReference

System.gc

idx += 1      // The onChange event will be printed out, because hard refference is kept

hardRef = null

System.gc

idx += 2     // The onChange event should be gone (cancelled), because refference is lost.
Source
__.scala