Skip to content

Commit

Permalink
Allow return values within revertable calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kettle11 committed Feb 24, 2023
1 parent 137bb4a commit b19ba2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tangle_ts/dist/tangle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tangle_ts/src/tangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class Tangle {
private _message_time_offset = 0;

private _last_sent_message = 0;
private _in_call_that_will_be_reverted = false;

// private _debug_enabled = true;

Expand All @@ -90,6 +91,10 @@ export class Tangle {
if (typeof importValue === 'function') {
moduleImports[importName] = function (...args: any) {
const r = importValue(...args);
// This call will be reverted so it's OK if it causes a temporary desync.
if (this._in_call_that_will_be_reverted) {
return r;
}
if (r !== undefined) {
console.log("[tangle warning] Tangle prevents WebAssembly imports from returning values because those values are unique per-peer and would cause a desync.")
}
Expand Down Expand Up @@ -321,7 +326,9 @@ export class Tangle {
this.call(key, ...args);
};
wrapped_function.callAndRevert = (...args: any) => {
this._in_call_that_will_be_reverted = true;
this.call_and_revert(key, ...args);
this._in_call_that_will_be_reverted = false;
};
export_object[key] = wrapped_function;
}
Expand Down

0 comments on commit b19ba2f

Please sign in to comment.