IntegerInSync

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

The IntegerInSync class holds one integer 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 count across lines: Add, Increase and Decrease never lose an update, unlike getting the value, adding, and setting it back.

Example Code

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

Actions

Add(integer 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 integer: How much to add; may be negative.

Returns

integer: The value after adding.

Example

use Libraries.Multitasking.Types.IntegerInSync

IntegerInSync total
total:Add(5)
integer current = total:Add(2)

Decrease()

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

Returns

integer: The value after taking one away.

Example

use Libraries.Multitasking.Types.IntegerInSync

IntegerInSync count
count:Decrease()

Get()

This action gets the value.

Returns

integer: The value.

Example

use Libraries.Multitasking.Types.IntegerInSync

IntegerInSync common
integer current = common:Get()

Increase()

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

Returns

integer: The value after adding one.

Example

use Libraries.Multitasking.Types.IntegerInSync

IntegerInSync count
count:Increase()

Set(integer value)

This action sets the value.

Parameters

  • value integer: The new value.

Example

use Libraries.Multitasking.Types.IntegerInSync

IntegerInSync common
common:Set(10)

Inherited Actions

3 actions from Libraries.Language.Object