@@ -7,6 +7,7 @@ import { mkTuple } from './ValuesUtil.mjs';
77import { SchedulerInterface } from './SchedulerInterface.mjs' ;
88import { RuntimeInterface } from './RuntimeInterface.mjs' ;
99import { LVal } from './Lval.mjs'
10+ import { Level } from "./Level.mjs" ;
1011import { ProcessID , pid_equals } from './process.mjs'
1112import SandboxStatus from './SandboxStatus.mjs'
1213import { ThreadError , TroupeError } from './TroupeError.mjs'
@@ -106,11 +107,18 @@ export class Scheduler implements SchedulerInterface {
106107 }
107108
108109 /** Create a new thread `t` for the given function to be evaluated and schedule it. */
109- scheduleNewThreadAtLevel ( thefun , arg , levpc , levblock , ismain = false , persist = null , isSystem = false ) {
110+ scheduleNewThreadAtLevel ( f : ( ) => any ,
111+ arg : any ,
112+ pc : Level ,
113+ block : Level ,
114+ ismain : boolean = false ,
115+ persist : boolean | null = null ,
116+ isSystem : boolean = false )
117+ {
110118 // Create a new process ID at the given level.
111119 const pid = isSystem ? SYSTEM_PROCESS_STRING : uuidv4 ( ) ;
112120 const pidObj = new ProcessID ( this . rt_uuid , pid , this . __node ) ;
113- const newPid = new LVal ( pidObj , levpc ) ;
121+ const newPid = new LVal ( pidObj , pc ) ;
114122
115123 // Epilogue for thread.
116124 const halt = ismain ? ( ) => { this . haltMain ( persist ) } :
@@ -120,10 +128,10 @@ export class Scheduler implements SchedulerInterface {
120128 const t = new Thread
121129 ( newPid
122130 , halt
123- , thefun
131+ , f
124132 , arg
125- , levpc
126- , levblock
133+ , pc
134+ , block
127135 , new SandboxStatus . NORMAL ( )
128136 , this . rtObj
129137 , this ) ;
@@ -134,9 +142,9 @@ export class Scheduler implements SchedulerInterface {
134142 return newPid ;
135143 }
136144
137- /** Schedule the given function as the very next thing to be run. */
138- schedule ( thefun , args , nm ) {
139- this . __currentThread . runNext ( thefun , args , nm ) ;
145+ /** Schedule the given function as the very next thing to be run on the current thread . */
146+ schedule ( f : ( ) => any , args : any , namespace : any ) {
147+ this . __currentThread . runNext ( f , args , namespace ) ;
140148 this . scheduleThread ( this . __currentThread ) ;
141149 }
142150
@@ -206,7 +214,7 @@ export class Scheduler implements SchedulerInterface {
206214 delete this . __alive [ this . __currentThread . tid . val . toString ( ) ] ;
207215 console . log ( ">>> Main thread finished with value:" , retVal . stringRep ( ) ) ;
208216 if ( persist ) {
209- this . rtObj . persist ( retVal , persist )
217+ this . rtObj . persist ( retVal , persist )
210218 console . log ( "Saved the result value in file" , persist )
211219 }
212220 return null ;
@@ -220,8 +228,8 @@ export class Scheduler implements SchedulerInterface {
220228 }
221229
222230 /** Kill thread `t` with the error message `s` sent to its monitors. */
223- stopThreadWithErrorMessage ( t : Thread , s : string ) {
224- this . notifyMonitors ( TerminationStatus . ERR , s ) ;
231+ stopThreadWithErrorMessage ( t : Thread , errMsg : string ) {
232+ this . notifyMonitors ( TerminationStatus . ERR , errMsg ) ;
225233 delete this . __alive [ t . tid . val . toString ( ) ] ;
226234 }
227235
0 commit comments