-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ev/deadline
and ev/with-deadline
should be documented better.
#1349
Comments
Not an answer, but may be some relevant code: while (peek_timeout(&to) && to.when <= now) {
pop_timeout(0);
if (to.curr_fiber != NULL) {
if (janet_fiber_can_resume(to.curr_fiber)) {
janet_cancel(to.fiber, janet_cstringv("deadline expired"));
}
} else {
/* This is a timeout (for a function call, not a whole fiber) */
if (to.fiber->sched_id == to.sched_id) {
if (to.is_error) {
janet_cancel(to.fiber, janet_cstringv("timeout"));
} else {
janet_schedule(to.fiber, janet_wrap_nil());
}
}
}
} Some further bits:
Some info about /* The current running fiber on the current thread.
* Set and unset by functions in vm.c */
JanetFiber *fiber;
JanetFiber *root_fiber; |
ev/deadline
and ev/with-deadlin
should be documented better.ev/deadline
and ev/with-deadline
should be documented better.
For reference, I've started to gather some more details about Once I've gotten a better understanding, I'm willing to work on addressing this issue. |
Ok, I've looked into this a bit more and have some results to share. (Note: I'm not done, this is a status update.) I'll start with sample code: (def check-wait 1.1)
(def cancel-wait (* 2 check-wait))
(def deadline (* 0.5 check-wait))
(var tocancel-fib nil)
(var tocheck-fib nil)
(set tocancel-fib
(ev/go
(fiber/new
(fn []
(print "tocancel: started")
(set tocheck-fib
(fiber/new
(fn []
(print "tocheck: started")
(printf "tocheck: waiting: %n sec" check-wait)
(ev/sleep check-wait)
(print "tocheck: ended"))))
(resume tocheck-fib)
(printf "tocancel: waiting: %n sec" cancel-wait)
(ev/sleep cancel-wait)
(print "tocancel: ended")))))
# yield so tocancel-fib can start
(ev/sleep 0)
(ev/deadline deadline tocancel-fib tocheck-fib) Output looked like:
It may or may not be obvious from the above, but I think that one thing it demonstrates is that It wasn't obvious to me initially from the docstring, but now that I think I understand more I see that this bit of text in the docstring:
implies that it must be a task (because non-task fibers are not canceled with My current leaning is that it might be better to have text along the lines of:
or:
immediately after:
|
As to what happens to So perhaps it's fair to claim that the current docstring says things along those lines:
As far as My current guess is that it may depend on its relationship to If, as in the sample code above, As far as |
Regarding:
I was looking at the docstrings for
and
I think if the deadline is reached, then
If (def tocancel
(ev/go (coro (yield 1))))
# let `tocancel` start by yielding to the event loop
(ev/sleep 0.1)
# try to cancel `tocancel`
(ev/cancel tocancel nil)
# sample output
#
# error:
# in <anonymous> [ev-cancel.janet] on line 2, column 16
It did take some looking things up and combining together, but in this case aren't all lookups within docstrings? Note that the website docs do contain coverage of cancellation wrt the event loop. There is even sample code there: (def f
(ev/spawn
(print "starting long io...")
(ev/sleep 10000)
(print "finished long io!")))
# wait 2 seconds before canceling the long IO.
(ev/sleep 2)
(ev/cancel f "canceled") When I put this code in a file (say
There is even accompanying text:
|
Based on looking into this matter with @llmII (and some of the original suggestions from @amano-kenji), the following text includes some modifications to the two docstrings in question. I'm thinking to make a PR based on the content.
Run a body of code with a deadline of
Set a deadline for a fiber If
If Returns With respect to what happens to IIUC, the caller of Please see this comment regarding:
I believe I have addressed it in that comment. [1] Though I have made a note that it might be good to add this kind of info to the website docs, possibly near or on the fiber page. |
(ev/with-deadline deadline & body)
,deadline
should becomesec
.(ev/deadline sec &opt tocancel tocheck)
, I don't know the difference betweentocancel
andtocheck
. If deadline is reached, what exactly happens totocheck
andtocancel
?ev/deadline
throws an error if deadline is reached. This behavior is not documented.The text was updated successfully, but these errors were encountered: