napi-rs/examples/napi/vite-entry.js

36 lines
626 B
JavaScript
Raw Permalink Normal View History

import { Buffer } from 'buffer'
2024-01-17 00:28:40 +09:00
import {
Animal,
Kind,
asyncMultiTwo,
tsfnReturnPromise,
__fs,
asyncTaskReadFile,
} from './example.wasi-browser'
2024-01-17 00:28:40 +09:00
global.Buffer = Buffer
2024-01-17 00:28:40 +09:00
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)
})