NumberInSync

Package: Libraries.Multitasking.Types · Inherits from: Libraries.Language.Object

The NumberInSync class holds one number that tasks on different lines may use at the same time. Each action is one step: no other line can change the value in the middle of it. Use it to add up amounts across lines: Add never loses an update, unlike getting the value, adding, and setting it back.

Example Code

use Libraries.Multitasking.Types.NumberInSync
class Main
action Main
    NumberInSync common
    common:Set(2.5)
    output common:Get()
end
end

Actions

Add(number amount)

This action adds an amount to the value, as one step, and returns the new value. Several lines adding at once never lose an addition.

Parameters

  • amount number: How much to add; may be negative.

Returns

number: The value after adding.

Example

use Libraries.Multitasking.Types.NumberInSync

NumberInSync total
total:Add(5)
number current = total:Add(2)

Decrease()

This action takes one from the value, as one step, and returns the new value.

Returns

number: The value after taking one away.

Example

use Libraries.Multitasking.Types.NumberInSync

NumberInSync count
count:Decrease()

Get()

This action gets the value.

Returns

number: The value.

Example

use Libraries.Multitasking.Types.NumberInSync

NumberInSync common
number current = common:Get()

Increase()

This action adds one to the value, as one step, and returns the new value.

Returns

number: The value after adding one.

Example

use Libraries.Multitasking.Types.NumberInSync

NumberInSync count
count:Increase()

Set(number value)

This action sets the value.

Parameters

  • value number: The new value.

Example

use Libraries.Multitasking.Types.NumberInSync

NumberInSync common
common:Set(2.5)

Inherited Actions

3 actions from Libraries.Language.Object