forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
napi_ref_threadsafe_function
(oven-sh#4156)
* Implement napi_ref_threadsafe_function * work on this * i hate event loops * little better * clean
- Loading branch information
1 parent
397182b
commit 6641198
Showing
10 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import fsevents from "fsevents"; | ||
|
||
if (process.argv.length < 3) { | ||
console.log("Usage: bun fsevents-event-loop.ts <directory>"); | ||
process.exit(1); | ||
} | ||
fsevents.watch(process.argv[2], () => { | ||
console.log("it works!"); | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { bunEnv, bunExe } from "harness"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
import os from "os"; | ||
|
||
test("fsevents works (napi_ref_threadsafe_function keeps event loop alive)", async () => { | ||
const tempFile = fs.mkdtempSync(path.join(os.tmpdir(), "fsevents-test-")); | ||
const spawned = Bun.spawn({ | ||
cmd: [bunExe(), "run", path.join(import.meta.dir, "fsevents-event-loop.mjs"), tempFile], | ||
env: bunEnv, | ||
stdio: ["pipe", "pipe", "pipe"], | ||
}); | ||
await Bun.sleep(50); | ||
if (spawned.killed) { | ||
throw new Error("event loop died, test failed"); | ||
} | ||
await Bun.write(tempFile + "/hello.txt", "test"); | ||
expect(await spawned.exited).toBe(0); | ||
expect(await new Response(spawned.stdout).text()).toBe("it works!\n"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "fsevents-test", | ||
"dependencies": { | ||
"fsevents": "2.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters