aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/event_loop.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/event_loop.zig')
-rw-r--r--src/bun.js/event_loop.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index 8441bd064..a3ccd16ad 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -224,6 +224,7 @@ pub const CppTask = opaque {
const ThreadSafeFunction = JSC.napi.ThreadSafeFunction;
const MicrotaskForDefaultGlobalObject = JSC.MicrotaskForDefaultGlobalObject;
const HotReloadTask = JSC.HotReloader.HotReloadTask;
+const FSWatchTask = JSC.Node.FSWatcher.FSWatchTask;
const PollPendingModulesTask = JSC.ModuleLoader.AsyncModule.Queue;
// const PromiseTask = JSInternalPromise.Completion.PromiseTask;
const GetAddrInfoRequestTask = JSC.DNS.GetAddrInfoRequest.Task;
@@ -242,6 +243,7 @@ pub const Task = TaggedPointerUnion(.{
HotReloadTask,
PollPendingModulesTask,
GetAddrInfoRequestTask,
+ FSWatchTask,
// PromiseTask,
// TimeoutTasklet,
});
@@ -467,6 +469,11 @@ pub const EventLoop = struct {
// special case: we return
return 0;
},
+ .FSWatchTask => {
+ var transform_task: *FSWatchTask = task.get(FSWatchTask).?;
+ transform_task.*.run();
+ transform_task.deinit();
+ },
@field(Task.Tag, typeBaseName(@typeName(AnyTask))) => {
var any: *AnyTask = task.get(AnyTask).?;
any.run();
@@ -666,6 +673,30 @@ pub const EventLoop = struct {
}
}
+ pub fn waitForPromiseWithTimeout(this: *EventLoop, promise: JSC.AnyPromise, timeout: u32) bool {
+ return switch (promise.status(this.global.vm())) {
+ JSC.JSPromise.Status.Pending => {
+ if (timeout == 0) {
+ return false;
+ }
+ var start_time = std.time.milliTimestamp();
+ while (promise.status(this.global.vm()) == .Pending) {
+ this.tick();
+
+ if (std.time.milliTimestamp() - start_time > timeout) {
+ return false;
+ }
+
+ if (promise.status(this.global.vm()) == .Pending) {
+ this.autoTick();
+ }
+ }
+ return true;
+ },
+ else => true,
+ };
+ }
+
pub fn waitForTasks(this: *EventLoop) void {
this.tick();
while (this.tasks.count > 0) {