46cbcf3ff1
* feat(cli): allow sync fs operation between workers/mainThread * allow sync fs operation between workers/mainThread (#2065) * Fix * Update fixture * flaky test * Fix cross compile target * Update zig * macos-cross test was filtered --------- Co-authored-by: Toyo Li <lifenglin314@outlook.com>
35 lines
626 B
JavaScript
35 lines
626 B
JavaScript
import { Buffer } from 'buffer'
|
|
|
|
import {
|
|
Animal,
|
|
Kind,
|
|
asyncMultiTwo,
|
|
tsfnReturnPromise,
|
|
__fs,
|
|
asyncTaskReadFile,
|
|
} from './example.wasi-browser'
|
|
|
|
global.Buffer = Buffer
|
|
|
|
console.info(new Animal(Kind.Cat, 'Tom'))
|
|
asyncMultiTwo(200).then((res) => {
|
|
console.info(res)
|
|
})
|
|
const value = await tsfnReturnPromise((err, value) => {
|
|
if (err) {
|
|
throw err
|
|
}
|
|
return Promise.resolve(value + 2)
|
|
})
|
|
|
|
console.info(value)
|
|
|
|
__fs.writeFileSync('/test.txt', 'Hello, World!')
|
|
|
|
asyncTaskReadFile('/test.txt')
|
|
.then((res) => {
|
|
console.log(`readFileAsync: ${res}`)
|
|
})
|
|
.catch((err) => {
|
|
console.error(err)
|
|
})
|