contents   index   previous   next



YIELDING AND SUSPENDING

 

At times, you may want to control the behavior of your fiber execution more than the simple controls executing a single statement at a time provides. Two methods are provided for you to do so. Both methods are invoked by a wrapper function to affect the execution of the fiber the wrapper functions is within.

 

When a wrapper function is ready to return, it sets up its value in the SE.RETURN object. Two members of the object, SE.YIELD and SE.SUSPEND, can likewise be set. Both are boolean members and are set true to invoke their relevent behavior.

 

First is SE.YIELD. By yielding, the fiber ensures that the current seExec statement is immediately ended. Recall that the SE.INFREQUENT_CONT option to seEval means that several statements are executed for each call to seExec. If a wrapper function yields, the seExec returns immediately. The return value for the wrapper function is still treated normally. The next time the fiber is executed using seExec, execution resumes with the code that called the wrapper function getting that value as the return.

 

The second option is SE.SUSPEND. Suspending functions is similar to yielding in that the calling seExec finishes immediately. However, the fiber is put into a suspended state. This means that further calls to seExec will immediately return without executing any code of the fiber. It is the job of your application to determine when the fiber is ready to be restored and remove its suspended state. This is done by assigning false to the fiber’s SE.RETURN,SE.SUSPEND member. After the suspend is removed, the application can also change the return value to be returned by the wrapper function before again executing any code. It does this by assigning the new value to the SE.RETURN,SE.VALUE member as normal. If it does not, the value returned by the wrapper function is used. This is useful if the value to be returned is unknown when the wrapper function suspended, perhaps that is why it needed to be suspended. Remember, though, that the SE.RETURN,SE.VALUE member is read-only as long as any of the boolean members is true including the SE.SUSPEND member. You must turn the suspension off before you are allowed to write a new return value. Of course, you must do it also before you call seExec on the fiber after it is unsuspended.

 


OTHER CONSIDERATIONS