kopia lustrzana https://github.com/micropython/micropython
Merge 01826acc96
into 01c31ea804
commit
50bd4c0712
|
@ -88,6 +88,20 @@ MicroPython code execution will suspend the browser so be sure to atomize usage
|
|||
within this environment. Unfortunately interrupts have not been implemented for the
|
||||
browser.
|
||||
|
||||
Running with WebWorkers on browsers
|
||||
-----------------
|
||||
To enable WebWorker support and receive messages outside of DOM, set `Module.webWorkerEventCallback` to a function that'll receive the events.
|
||||
|
||||
```
|
||||
importScripts('micropython.js');
|
||||
// ...
|
||||
Module.webWorkerEventCallback = (event) => {
|
||||
console.log(`Received an event from MicroPython!`);
|
||||
};
|
||||
```
|
||||
|
||||
WebWorkers on the web gives more flexibility to developers when consuming the WASM module. Example cases where this is useful are: not blocking main thread, creating and disposing multiple instances on a single session, using multiple instances for different purposes separate from each other...
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
mergeInto(LibraryManager.library, {
|
||||
mp_js_write: function(ptr, len) {
|
||||
const buffer = HEAPU8.subarray(ptr, ptr + len)
|
||||
if (ENVIRONMENT_IS_NODE) {
|
||||
if (ENVIRONMENT_IS_WORKER && typeof Module.webWorkerEventCallback === 'function') {
|
||||
Module.webWorkerEventCallback({detail: buffer});
|
||||
} else if (ENVIRONMENT_IS_NODE) {
|
||||
process.stdout.write(buffer);
|
||||
} else {
|
||||
const printEvent = new CustomEvent('micropython-print', { detail: buffer });
|
||||
|
|
|
@ -35,7 +35,7 @@ var mainProgram = function()
|
|||
|
||||
MP_JS_EPOCH = Date.now();
|
||||
|
||||
if (typeof window === 'undefined' && require.main === module) {
|
||||
if (ENVIRONMENT_IS_NODE && require.main === module) {
|
||||
var fs = require('fs');
|
||||
var heap_size = 128 * 1024;
|
||||
var contents = '';
|
||||
|
|
Ładowanie…
Reference in New Issue