zigar.thread.end() ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
Discontinue the handling of call requests from other threads, allowing for normal shutdown of the event loop on the PHP side.
Usage
const std = @import("std");
const zigar = @import("zigar");
pub fn startup() !void {
try zigar.thread.use();
}
pub fn spawn(cb: *const fn () void) !void {
const thread = try std.Thread.spawn(.{}, run, .{cb});
thread.detach();
}
fn run(cb: *const fn () void) void {
cb();
}
pub fn shutdown() void {
zigar.thread.end();
}
<?php
require __DIR__ . '/vendor/autoload.php';
use Revolt\EventLoop;
ini_set('zigar.event_loop', 'revolt');
EventLoop::defer(function() {
$m = zigar_use(__DIR__ . '/thread-example-1.zig');
$m->startup();
try {
$m->spawn(function() {
echo "Hello world\n";
});
// wait two seconds
$suspension = EventLoop::getSuspension();
EventLoop::delay(2, function() use($suspension) {
$suspension->resume();
});
$suspension->suspend();
} finally {
$m->shutdown();
}
});
EventLoop::run();
Hello world
Return value:
void