Skip to content

Commit

Permalink
Merge branch 'main' into don/test/dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored Jan 8, 2025
2 parents 911b2e1 + 043cb7f commit 3be0cb4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/api/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ setTimeout(() => {

When you're done with a JSCallback, you should call `close()` to free the memory.

### Experimental thread-safe callbacks
`JSCallback` has experimental support for thread-safe callbacks. This will be needed if you pass a callback function into a different thread from it's instantiation context. You can enable it with the optional `threadsafe` option flag.
```ts
const searchIterator = new JSCallback(
(ptr, length) => /hello/.test(new CString(ptr, length)),
{
returns: "bool",
args: ["ptr", "usize"],
threadsafe: true, // Optional. Defaults to `false`
},
);
```
Be aware that there are still cases where this does not 100% work.

{% callout %}

**⚡️ Performance tip** — For a slight performance boost, directly pass `JSCallback.prototype.ptr` instead of the `JSCallback` object:
Expand Down
14 changes: 11 additions & 3 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async function runTests() {
if (!failedResults.length) {
for (const testPath of tests) {
const title = relative(cwd, join(testsPath, testPath)).replace(/\\/g, "/");
if (title.startsWith("test/js/node/test/parallel/")) {
if (isNodeParallelTest(testPath)) {
await runTest(title, async () => {
const { ok, error, stdout } = await spawnBun(execPath, {
cwd: cwd,
Expand Down Expand Up @@ -850,12 +850,20 @@ function isJavaScriptTest(path) {
return isJavaScript(path) && /\.test|spec\./.test(basename(path));
}

/**
* @param {string} testPath
* @returns {boolean}
*/
function isNodeParallelTest(testPath) {
return testPath.replaceAll(sep, "/").includes("js/node/test/parallel/")
}

/**
* @param {string} path
* @returns {boolean}
*/
function isTest(path) {
if (path.replaceAll(sep, "/").startsWith("js/node/test/parallel/") && targetDoesRunNodeTests()) return true;
if (isNodeParallelTest(path) && targetDoesRunNodeTests()) return true;
if (path.replaceAll(sep, "/").startsWith("js/node/cluster/test-") && path.endsWith(".ts")) return true;
return isTestStrict(path);
}
Expand Down Expand Up @@ -1035,7 +1043,7 @@ function getRelevantTests(cwd) {
const filteredTests = [];

if (options["node-tests"]) {
tests = tests.filter(testPath => testPath.includes("js/node/test/parallel/"));
tests = tests.filter(isNodeParallelTest);
}

const isMatch = (testPath, filter) => {
Expand Down

0 comments on commit 3be0cb4

Please sign in to comment.