Crate quickjs_runtime[−][src]
quickjs_runtime
This crate is made up of two main parts:
- thread-safe utils and wrappers you can call these from any thread, all logic is directed to a single worker-thread which talks to the quickjs API
- quickjs bindings and utils these talk to the quickjs API directly and need to run in the same thread as the Runtime
Noteworthy structs
These are the structs you’ll use the most
Thread safe | Runtime Thread-local |
---|---|
EsRuntime the ‘starting point’ | QuickJsRuntime the wrapper for all things quickjs |
EsValueFacade copy of or reference to a value in the Runtime | JSValueRef reference counting pointer to a Value |
Doing something in the runtime worker thread
You always start with building a new EsRuntime
use quickjs_runtime::esruntimebuilder::EsRuntimeBuilder;
let rt: EsRuntime = EsRuntimeBuilder::new().build();
EsRuntime has plenty public methods you can check out but one of the things you’ll need to understand is how to communicate with the QuickJsRuntime This is done by adding a job to the EventQueue of the EsRuntime
use quickjs_runtime::quickjsruntime::QuickJsRuntime;
let res = rt.add_to_event_queue(|q_js_rt: &QuickJsRuntime| {
// this will run in the Worker thread, here we can use the quickjs API
return true;
}).await;
All the non-sync functions return a Future so you can .await them from async functions.
In order to do something and get the result synchronously you can use the sync variant
use quickjs_runtime::quickjsruntime::QuickJsRuntime;
let res = rt.add_to_event_queue_sync(|q_js_rt: &QuickJsRuntime| {
// this will run in the Worker thread, here we can use the quickjs API
return 1;
});
For more details and examples please explore the packages below
Modules
eserror | |
esruntime | |
esruntime_utils | |
esruntimebuilder | |
esscript | |
esvalue | |
features | |
quickjs_utils | |
quickjscontext | |
quickjsruntime | |
reflection | |
utils | |
valueref |
Macros
es_args |