Synchronisation via Conditions

class usim.Flag[source]

Explicitly settable condition

await set(to: bool = True)[source]

Set the boolean value of this condition

class usim.Tracked(value: usim._basics.tracked.V)[source]

A mutable value whose changes are tracked to generate and trigger events

The purpose of a tracked value is to derive notification points on the fly. Comparison and mathematical expressions define and trigger events, respectively:

async def refill(coffee: Tracked[float]):
    while True:
        # boolean expression providing an event to wait for
        await (coffee < 0.1)
        print('Coffee is low! Initiating emergency refill!')
        # arithmetic expression triggering events of waiters
        await (coffee + 0.9)
        print('Coffee refilled! Emergency resolved!')

The purpose of Tracked is to make operations asynchronous - the actual operations are taken from the wrapped value. This dictates both the availability and effect of operations.

Tracked does not require its underlying value to be mutable. Instead, the underlying value is replaced when Tracked changes - for example, await (tracked + 5) is a shorthand for await tracked.set(tracked.value + 5). This works both for immutable types, such as int, and mutable types, such as list.

Tracked assumes sole responsibility for changing value. This means that value should be changed only via set() or async operators, such as await (tracked + 3). Circumventing this to change a mutable value directly prevents Tracked from detecting the change and triggering events.

await set(to: usim._basics.tracked.V)[source]

Set the value

property value: usim._basics.tracked.V

The current value