mirror of
https://github.com/Z3Prover/z3
synced 2026-01-05 02:28:45 +00:00
Add WebAssembly/TypeScript bindings (#5762)
* Add TypeScript bindings * mark Z3_eval_smtlib2_string as async
This commit is contained in:
parent
9ac57fc510
commit
2b934b601d
18 changed files with 1722 additions and 33 deletions
38
src/api/js/src/async-wrapper.js
Normal file
38
src/api/js/src/async-wrapper.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// this wrapper works with async-fns to provide promise-based off-thread versions of some functions
|
||||
|
||||
let capability = null;
|
||||
function resolve_async(val) {
|
||||
// setTimeout is a workaround for https://github.com/emscripten-core/emscripten/issues/15900
|
||||
if (capability == null) {
|
||||
return;
|
||||
}
|
||||
let cap = capability;
|
||||
capability = null;
|
||||
|
||||
setTimeout(() => {
|
||||
cap.resolve(val);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function reject_async(val) {
|
||||
if (capability == null) {
|
||||
return;
|
||||
}
|
||||
let cap = capability;
|
||||
capability = null;
|
||||
|
||||
setTimeout(() => {
|
||||
cap.reject(val);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
Module.async_call = function (f, ...args) {
|
||||
if (capability !== null) {
|
||||
throw new Error(`you can't execute multiple async functions at the same time; let the previous one finish first`);
|
||||
}
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
capability = { resolve, reject };
|
||||
});
|
||||
f(...args);
|
||||
return promise;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue