mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
[bun.js] Add a Server.stop function
This commit is contained in:
@@ -312,6 +312,7 @@ pub const Task = TaggedPointerUnion(.{
|
||||
OpenAndStatFileTask,
|
||||
CopyFilePromiseTask,
|
||||
WriteFileTask,
|
||||
AnyTask,
|
||||
// PromiseTask,
|
||||
// TimeoutTasklet,
|
||||
});
|
||||
@@ -433,6 +434,30 @@ pub const SavedSourceMap = struct {
|
||||
};
|
||||
const uws = @import("uws");
|
||||
|
||||
pub const AnyTask = struct {
|
||||
ctx: *anyopaque,
|
||||
callback: fn (*anyopaque) void,
|
||||
|
||||
pub fn run(this: *AnyTask) void {
|
||||
this.callback(this.ctx);
|
||||
}
|
||||
|
||||
pub fn New(comptime Type: type, comptime Callback: anytype) type {
|
||||
return struct {
|
||||
pub fn init(ctx: *Type) AnyTask {
|
||||
return AnyTask{
|
||||
.callback = wrap,
|
||||
.ctx = ctx,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn wrap(this: *anyopaque) void {
|
||||
Callback(@ptrCast(*Type, @alignCast(@alignOf(Type), this)));
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// If you read JavascriptCore/API/JSVirtualMachine.mm - https://github.com/WebKit/WebKit/blob/acff93fb303baa670c055cb24c2bad08691a01a0/Source/JavaScriptCore/API/JSVirtualMachine.mm#L101
|
||||
// We can see that it's sort of like std.mem.Allocator but for JSGlobalContextRef, to support Automatic Reference Counting
|
||||
// Its unavailable on Linux
|
||||
@@ -583,6 +608,12 @@ pub const VirtualMachine = struct {
|
||||
finished += 1;
|
||||
vm_.active_tasks -|= 1;
|
||||
},
|
||||
@field(Task.Tag, @typeName(AnyTask)) => {
|
||||
var any: *AnyTask = task.get(AnyTask).?;
|
||||
any.run();
|
||||
finished += 1;
|
||||
vm_.active_tasks -|= 1;
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@@ -1677,12 +1708,7 @@ pub const VirtualMachine = struct {
|
||||
var promise: *JSInternalPromise = undefined;
|
||||
|
||||
promise = JSModuleLoader.loadAndEvaluateModule(this.global, &ZigString.init(entry_path));
|
||||
|
||||
this.tick();
|
||||
|
||||
while (promise.status(this.global.vm()) == JSPromise.Status.Pending) {
|
||||
this.tick();
|
||||
}
|
||||
this.waitForPromise(promise);
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user