2020-08-24 17:16:35 +09:00
|
|
|
import test from 'ava'
|
|
|
|
|
|
|
|
import { napiVersion } from '../napi-version'
|
2020-07-03 01:31:50 +09:00
|
|
|
|
|
|
|
const bindings = require('../../index.node')
|
2020-06-19 21:42:18 +09:00
|
|
|
|
|
|
|
test('should get js function called from a thread', async (t) => {
|
|
|
|
let called = 0
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
if (napiVersion < 4) {
|
|
|
|
t.is(bindings.testThreadsafeFunction, undefined)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-24 19:01:55 +09:00
|
|
|
await new Promise((resolve, reject) => {
|
2020-08-24 17:16:35 +09:00
|
|
|
bindings.testThreadsafeFunction((...args: any[]) => {
|
2020-06-19 21:42:18 +09:00
|
|
|
called += 1
|
|
|
|
try {
|
2020-07-03 01:36:45 +09:00
|
|
|
t.deepEqual(args, [null, 42, 1, 2, 3])
|
2020-06-19 21:42:18 +09:00
|
|
|
} catch (err) {
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (called === 2) {
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|