mirror of
https://github.com/janet-lang/janet
synced 2024-12-24 23:40:27 +00:00
Doc tweaks for ev/deadline and ev/with-deadline
This commit is contained in:
parent
03ae2ec153
commit
592ac4904c
@ -3736,12 +3736,20 @@
|
|||||||
~(,ev/thread (fn _spawn-thread [&] ,;body) nil :n))
|
~(,ev/thread (fn _spawn-thread [&] ,;body) nil :n))
|
||||||
|
|
||||||
(defmacro ev/with-deadline
|
(defmacro ev/with-deadline
|
||||||
`Run a body of code with a deadline, such that if the code does not complete before
|
``
|
||||||
the deadline is up, it will be canceled.`
|
Create a fiber to execute `body`, schedule the event loop to cancel
|
||||||
[deadline & body]
|
the task (root fiber) associated with `body`'s fiber, and start
|
||||||
|
`body`'s fiber by resuming it.
|
||||||
|
|
||||||
|
The event loop will try to cancel the root fiber if `body`'s fiber
|
||||||
|
has not completed after at least `sec` seconds.
|
||||||
|
|
||||||
|
`sec` is a number that can have a fractional part.
|
||||||
|
``
|
||||||
|
[sec & body]
|
||||||
(with-syms [f]
|
(with-syms [f]
|
||||||
~(let [,f (coro ,;body)]
|
~(let [,f (coro ,;body)]
|
||||||
(,ev/deadline ,deadline nil ,f)
|
(,ev/deadline ,sec nil ,f)
|
||||||
(,resume ,f))))
|
(,resume ,f))))
|
||||||
|
|
||||||
(defn- cancel-all [chan fibers reason]
|
(defn- cancel-all [chan fibers reason]
|
||||||
|
@ -2952,10 +2952,15 @@ JANET_CORE_FN(cfun_ev_sleep,
|
|||||||
|
|
||||||
JANET_CORE_FN(cfun_ev_deadline,
|
JANET_CORE_FN(cfun_ev_deadline,
|
||||||
"(ev/deadline sec &opt tocancel tocheck)",
|
"(ev/deadline sec &opt tocancel tocheck)",
|
||||||
"Set a deadline for a fiber `tocheck`. If `tocheck` is not finished after `sec` seconds, "
|
"Schedules the event loop to try to cancel the `tocancel` "
|
||||||
"`tocancel` will be canceled as with `ev/cancel`. "
|
"task as with `ev/cancel`. After `sec` seconds, the event "
|
||||||
"If `tocancel` and `tocheck` are not given, they default to `(fiber/root)` and "
|
"loop will attempt cancellation of `tocancel` if the "
|
||||||
"`(fiber/current)` respectively. Returns `tocancel`.") {
|
"`tocheck` fiber is resumable. `sec` is a number that can "
|
||||||
|
"have a fractional part. `tocancel` defaults to "
|
||||||
|
"`(fiber/root)`, but if specified, must be a task (root "
|
||||||
|
"fiber). `tocheck` defaults to `(fiber/current)`, but if "
|
||||||
|
"specified, should be a fiber. Returns `tocancel` "
|
||||||
|
"immediately.") {
|
||||||
janet_arity(argc, 1, 3);
|
janet_arity(argc, 1, 3);
|
||||||
double sec = janet_getnumber(argv, 0);
|
double sec = janet_getnumber(argv, 0);
|
||||||
JanetFiber *tocancel = janet_optfiber(argv, argc, 1, janet_vm.root_fiber);
|
JanetFiber *tocancel = janet_optfiber(argv, argc, 1, janet_vm.root_fiber);
|
||||||
|
Loading…
Reference in New Issue
Block a user