napi-rs/test_module/future.js

27 lines
542 B
JavaScript
Raw Normal View History

const testModule = require('./index.node')
2020-02-19 00:05:13 +09:00
function testSpawn() {
console.log('=== Test spawning a future on libuv event loop')
return testModule.testSpawn()
}
function testThrow() {
console.log('=== Test throwing from Rust')
try {
testModule.testThrow()
console.log('Expected function to throw an error')
process.exit(1)
2020-02-19 00:05:13 +09:00
} catch (e) {
console.log(e)
2020-02-19 00:05:13 +09:00
}
}
testSpawn()
.then((value) => {
console.info(`${value} from napi`)
testThrow()
})
.catch((e) => {
2020-02-19 00:05:13 +09:00
console.error(e)
process.exit(1)
})