-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix output race condition (fixes #4)
use a unified callback for both stdout and stderr
- Loading branch information
1 parent
c06f5fd
commit 645700e
Showing
4 changed files
with
6,960 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
globalThis.module = { exports: {} }; | ||
await import('./builder.bc.js'); | ||
console.log('hi'); | ||
console.log(JSON.stringify(Object.keys(globalThis.module.exports))); | ||
|
||
import * as pako from './lib/pako.esm.mjs'; | ||
|
||
const IS_NODE = typeof self !== 'object'; | ||
const fs = IS_NODE ? await import('fs') : null; | ||
const path = IS_NODE ? await import('path') : null; | ||
|
||
export const marshal = () => { | ||
if (!IS_NODE) throw Error("marshalling only supported on node"); | ||
|
||
console.log('marshalling aslp environment...'); | ||
const arr = pako.gzip(libASL_builder.marshal(libASL_builder.force())); | ||
|
||
let marshalUrl; | ||
if (IS_NODE) { | ||
fs.writeFileSync('aslp.heap', Buffer.from(arr)); | ||
marshalUrl = path.resolve('.', 'aslp.heap'); | ||
|
||
} else { | ||
marshalUrl = URL.createObjectURL( | ||
new File( | ||
[arr], | ||
'aslp.heap', | ||
{ lastModified: Date.now(), type: 'application/octet-stream' })); | ||
|
||
} | ||
console.log(marshalUrl); | ||
}; | ||
|
||
|
||
export const unmarshal = async (/* ArrayBuffer */ buf) => { | ||
try { | ||
const arr = pako.ungzip(new Uint8Array(buf)); | ||
|
||
libASL_web.unmarshal(arr); | ||
console.log(`heap loaded: ${arr.length} bytes, ${buf.byteLength} compressed`); | ||
|
||
} catch (e) { | ||
console.warn('failed to fetch heap'); | ||
console.warn(e); | ||
} | ||
}; | ||
|
||
if (IS_NODE) { | ||
marshal(); | ||
} |
Oops, something went wrong.