Skip to content

Commit

Permalink
webassembly: Make mp_js_process_char asynchronous.
Browse files Browse the repository at this point in the history
This may also call the garbage collector.

Signed-off-by: Eli Bierman <eli@elib.dev>
  • Loading branch information
elibdev authored and dpgeorge committed Jun 27, 2023
1 parent b2ad7e2 commit 813d559
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ports/webassembly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Initialize MicroPython repl. Must be called before entering characters into
the repl.

```
mp_js_process_char(char)
await mp_js_process_char(char)
```

Input character into MicroPython repl. `char` must be of type `number`. This
Expand Down
10 changes: 6 additions & 4 deletions ports/webassembly/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var mainProgram = function()
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string'], {async: true});
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number'], {async: true});

MP_JS_EPOCH = Date.now();

Expand Down Expand Up @@ -69,9 +69,11 @@ var mainProgram = function()
process.stdin.setRawMode(true);
process.stdin.on('data', function (data) {
for (var i = 0; i < data.length; i++) {
if (mp_js_process_char(data[i])) {
process.exit()
}
mp_js_process_char(data[i]).then(result => {
if (result) {
process.exit()
}
})
}
});
} else {
Expand Down

0 comments on commit 813d559

Please sign in to comment.