MCPcopy Create free account
hub / github.com/dfinity/ic-repl / apply_func

Function apply_func

src/exp.rs:905–928  ·  view source on GitHub ↗
(helper: &MyHelper, func: &str, args: Vec<IDLValue>)

Source from the content-addressed store, hash-verified

903}
904
905pub fn apply_func(helper: &MyHelper, func: &str, args: Vec<IDLValue>) -> Result<IDLValue> {
906 match helper.func_env.0.get(func) {
907 None => Err(anyhow!("Unknown function {}", func)),
908 Some((formal_args, body)) => {
909 if formal_args.len() != args.len() {
910 return Err(anyhow!(
911 "{} expects {} arguments, but {} is provided",
912 func,
913 formal_args.len(),
914 args.len()
915 ));
916 }
917 let mut helper = helper.spawn();
918 for (id, v) in formal_args.iter().zip(args) {
919 helper.env.0.insert(id.to_string(), v);
920 }
921 for cmd in body.iter() {
922 cmd.clone().run(&mut helper)?;
923 }
924 let res = helper.env.0.get("_").unwrap_or(&IDLValue::Null).clone();
925 Ok(res)
926 }
927 }
928}
929#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
930async fn parallel_calls(
931 futures: Vec<impl std::future::Future<Output = anyhow::Result<IDLArgs>>>,

Callers 2

replFunction · 0.85
evalMethod · 0.85

Calls 3

getMethod · 0.80
spawnMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected