Skip to content

Commit

Permalink
support async_hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jan 24, 2023
1 parent 2045955 commit 153baeb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
16 changes: 14 additions & 2 deletions lib/sqlite3-binding.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const binary = require('@mapbox/node-pre-gyp');
const path = require('path');
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), {
target_arch: process.env.npm_config_target_arch || process.env.npm_config_arch || process.arch
});
let binding = require(binding_path);
if (typeof binding === 'function') {
const emnapiContext = require('@tybys/emnapi-runtime').createContext();
binding = binding().emnapiInit({ context: emnapiContext });
const emnapiInitOptions = {
context: emnapiContext
};
try {
// optional dependency
// support async_hooks on Node.js
emnapiInitOptions.nodeBinding = require('@tybys/emnapi-node-binding');
} catch (_) {
// ignore
}
binding = binding().emnapiInit(emnapiInitOptions);
}
module.exports = exports = binding;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"@tybys/emnapi-runtime": "^0.28.1",
"node-addon-api": "^4.2.0",
"tar": "^6.1.11"
},
"devDependencies": {
"@tybys/emnapi": "^0.27.0",
"@tybys/emnapi-runtime": "^0.27.0",
"@tybys/emnapi": "^0.28.1",
"eslint": "6.8.0",
"mocha": "7.2.0",
"node-pre-gyp-github": "1.4.4"
Expand All @@ -68,6 +68,7 @@
}
},
"optionalDependencies": {
"@tybys/emnapi-node-binding": "^0.28.1",
"node-gyp": "8.x"
},
"scripts": {
Expand Down
11 changes: 5 additions & 6 deletions test/async_calls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ const { createHook, executionAsyncId } = require("async_hooks");


describe('async_hooks', function() {
before(function() {
if (process.env.npm_config_arch.includes('wasm')) {
// async_hooks is not supported by emnapi
this.skip();
}
});
// before(function() {
// if (process.env.npm_config_arch.includes('wasm')) {
// this.skip();
// }
// });

let db;
let dbId;
Expand Down

0 comments on commit 153baeb

Please sign in to comment.