Replies: 1 comment
-
Roughly, first you need to specify a job executor when creating the context: let mut context = ContextBuilder::new()
.job_executor(executor)
.build().unwrap() Then after running your script you need to run the async jobs to completion: context
.run_jobs_async()
.await
.unwrap(); Or use There are examples of implementing an executor here (not in an async runtime) and here (using tokio). You can probably just copy-paste them. Note this is using the latest on main at time of writing, which is different from v0.20. In v0.20 it used a JobQueue like here. I'm not sure if the other steps differ (I vaguely recall you may have to call Finally you can look at the promise result, something like: let maybe_promise = res.as_promise();
match maybe_promise {
Some(promise) => match promise.state() {
PromiseState::Pending => panic!("Promise is still pending"),
PromiseState::Fulfilled(result) => Ok(result), // Do something with JsValue
PromiseState::Rejected(error) => Err(e.to_string()),
},
None => Ok(res),
} I'm just figuring this stuff out myself, so take the advice with a grain of salt. |
Beta Was this translation helpful? Give feedback.
-
How to get the result of JavaScript execution in the test_javascript async method?
result is
should be. is
rust eval:200 OK
Beta Was this translation helpful? Give feedback.
All reactions