@@ -47,6 +47,14 @@ struct Run: ParsableCommand {
4747    @Option ( name:  . customLong( " dir " ) ,  help:  " Grant access to the given host directory " )  
4848    var  directories :  [ String ]  =  [ ] 
4949
50+     enum  ThreadingModel :  String ,  ExpressibleByArgument  { 
51+         case  direct
52+         case  token
53+     } 
54+ 
55+     @Option ( help:  ArgumentHelp ( " The execution threading model to use " ,  visibility:  . hidden) )  
56+     var  threadingModel :  ThreadingModel ? 
57+ 
5058    @Argument  
5159    var  path :  String 
5260
@@ -134,6 +142,16 @@ struct Run: ParsableCommand {
134142        return  nil 
135143    } 
136144
145+     private  func  deriveRuntimeConfiguration( )  ->  RuntimeConfiguration  { 
146+         let  threadingModel :  RuntimeConfiguration . ThreadingModel ? 
147+         switch  self . threadingModel { 
148+         case  . direct:  threadingModel =  . direct
149+         case  . token:  threadingModel =  . token
150+         case  nil :  threadingModel =  nil 
151+         } 
152+         return  RuntimeConfiguration ( threadingModel:  threadingModel) 
153+     } 
154+ 
137155    func  instantiateWASI( module:  Module ,  interceptor:  RuntimeInterceptor ? )  throws  ->  ( )  throws  ->  Void  { 
138156        // Flatten environment variables into a dictionary (Respect the last value if a key is duplicated)
139157        let  environment  =  environment. reduce ( into:  [ String:  String] ( ) )  { 
@@ -143,7 +161,7 @@ struct Run: ParsableCommand {
143161            $0 [ $1]  =  $1
144162        } 
145163        let  wasi  =  try   WASIBridgeToHost ( args:  [ path]  +  arguments,  environment:  environment,  preopens:  preopens) 
146-         let  runtime  =  Runtime ( hostModules:  wasi. hostModules,  interceptor:  interceptor) 
164+         let  runtime  =  Runtime ( hostModules:  wasi. hostModules,  interceptor:  interceptor,  configuration :   deriveRuntimeConfiguration ( ) ) 
147165        let  moduleInstance  =  try   runtime. instantiate ( module:  module) 
148166        return  { 
149167            let  exitCode  =  try   wasi. start ( moduleInstance,  runtime:  runtime) 
@@ -174,7 +192,7 @@ struct Run: ParsableCommand {
174192            return  nil 
175193        } 
176194
177-         let  runtime  =  Runtime ( interceptor:  interceptor) 
195+         let  runtime  =  Runtime ( interceptor:  interceptor,  configuration :   deriveRuntimeConfiguration ( ) ) 
178196        let  moduleInstance  =  try   runtime. instantiate ( module:  module) 
179197        return  { 
180198            log ( " Started invoking function  \" \( functionName) \"  with parameters:  \( parameters) " ,  verbose:  true ) 
0 commit comments