C# Class kOS.Safe.Execution.YieldFinishedDetector

When telling kOS's CPU that it should yield, using the CPU.YieldProgram() method, you make a new instance of a derivative of this class to manage the decision of when it should resume again. kOS's CPU will repeatedly re-check the instance of this class whenever it wants to execute Opcodes, and only when this class says so will it resume execution of the Opcodes.

When you make a new instance of this class you should immediately "forget" it after it is passed to YieldProgram() (i.e. don't hold a reference to it.) If you call YieldProgram() again, it should always be a with a new instance of this class.

When you inherit from this class, you should store any data values that are part of the decision "am I done waiting" as members of this class, such that each new instance gets its own set of such fields and all instances can decide "am I done" indepentantly of each other.

The reason all the above instructions are relevant is that they allow the same Opcode, or Built-in Function to cause more than one YieldProgram to exist similtaneously from them.
(i.e. a Wait Opcode inside a function, and that function gets called from both the mainline code and a trigger. You want two different wait timers going for them even though they're coming from the exact same OpcodeWait instance in the program.)
Show file Open project: KSP-KOS/KOS Class Usage Examples

Public Methods

Method Description
Begin ( SafeSharedObjects shared ) : void

When the CPU starts the yield, it will call Begin to tell you the shared objects handle in case you need some information from it, and to let you get anything you like started up, like a timer for example.

You can be guaranteed that the CPU will call Begin() before it ever calls IsFinished(), so it's safe for IsFinished() to use information that was obtained from Begin().

IsFinished ( ) : bool

Track whatever you feel like in this class to decide when the wait is over, but this is how you tell the CPU the wait is over. The CPU will call IsFinished() over and over to find out when it's time to start executing opcodes again.

You can be guaranteed that the CPU will call Begin() before it ever calls IsFinished(), so it's safe for IsFinished() to use information that was obtained from Begin().

Method Details

Begin() public abstract method

When the CPU starts the yield, it will call Begin to tell you the shared objects handle in case you need some information from it, and to let you get anything you like started up, like a timer for example.

You can be guaranteed that the CPU will call Begin() before it ever calls IsFinished(), so it's safe for IsFinished() to use information that was obtained from Begin().
public abstract Begin ( SafeSharedObjects shared ) : void
shared SafeSharedObjects
return void

IsFinished() public abstract method

Track whatever you feel like in this class to decide when the wait is over, but this is how you tell the CPU the wait is over. The CPU will call IsFinished() over and over to find out when it's time to start executing opcodes again.

You can be guaranteed that the CPU will call Begin() before it ever calls IsFinished(), so it's safe for IsFinished() to use information that was obtained from Begin().
public abstract IsFinished ( ) : bool
return bool