mirror of
https://github.com/janet-lang/janet
synced 2025-10-24 20:27:41 +00:00
@@ -2004,7 +2004,6 @@ error:
|
||||
|
||||
static void janet_ev_go(JanetFiber *fiber, Janet value, JanetChannel *supervisor_channel) {
|
||||
fiber->supervisor_channel = supervisor_channel;
|
||||
/* janet_channel_push(supervisor_channel, make_supervisor_event("new", fiber), 2); */
|
||||
janet_schedule(fiber, value);
|
||||
}
|
||||
|
||||
@@ -2031,6 +2030,17 @@ static Janet cfun_ev_call(int32_t argc, Janet *argv) {
|
||||
return janet_wrap_fiber(fiber);
|
||||
}
|
||||
|
||||
static Janet cfun_ev_give_supervisor(int32_t argc, Janet *argv) {
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetChannel *chan = janet_vm_root_fiber->supervisor_channel;
|
||||
if (NULL != chan) {
|
||||
if (janet_channel_push(chan, janet_wrap_tuple(janet_tuple_n(argv, argc)), 0)) {
|
||||
janet_await();
|
||||
}
|
||||
}
|
||||
return janet_wrap_nil();
|
||||
}
|
||||
|
||||
JANET_NO_RETURN void janet_sleep_await(double sec) {
|
||||
JanetTimeout to;
|
||||
to.when = ts_delta(ts_now(), sec);
|
||||
@@ -2139,6 +2149,13 @@ static const JanetReg ev_cfuns[] = {
|
||||
"events occur in the newly scheduled fiber, an event will be pushed to the supervisor. "
|
||||
"If not provided, the new fiber will inherit the current supervisor.")
|
||||
},
|
||||
{
|
||||
"ev/give-supervisor", cfun_ev_give_supervisor,
|
||||
JDOC("(ev/give-supervsior tag & payload)\n\n"
|
||||
"Send a message to the current supervior channel if there is one. The message will be a "
|
||||
"tuple of all of the arguments combined into a single message, where the first element is tag. "
|
||||
"By convention, tag should be a keyword indicating the type of message. Returns nil.")
|
||||
},
|
||||
{
|
||||
"ev/sleep", cfun_ev_sleep,
|
||||
JDOC("(ev/sleep sec)\n\n"
|
||||
|
||||
Reference in New Issue
Block a user