erlang: receive...after Ms timeout clause (+9 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 21:01:39 +00:00
parent d191f7cd9e
commit e2e801e38a
4 changed files with 125 additions and 6 deletions

View File

@@ -193,6 +193,8 @@
:continuation nil
:receive-pats nil
:trap-exit false
:has-timeout false
:timed-out false
:exit-reason nil}))
(dict-set! (er-sched-processes) (er-pid-key pid) proc)
(er-sched-enqueue! pid)
@@ -292,10 +294,40 @@
()
(let
((pid (er-sched-next-runnable!)))
(when
(cond
(not (= pid nil))
(er-sched-step! pid)
(er-sched-run-all!)))))
(do (er-sched-step! pid) (er-sched-run-all!))
;; Queue empty — fire one pending receive-with-timeout and go again.
(er-sched-fire-one-timeout!) (er-sched-run-all!)
:else nil))))
;; Wake one waiting process whose receive had an `after Ms` clause.
;; Returns true if one fired. In our synchronous model "time passes"
;; once the runnable queue drains — timeouts only fire then.
(define
er-sched-fire-one-timeout!
(fn
()
(let
((ks (keys (er-sched-processes))) (fired (list false)))
(for-each
(fn
(k)
(when
(not (nth fired 0))
(let
((p (get (er-sched-processes) k)))
(when
(and
(= (get p :state) "waiting")
(get p :has-timeout))
(dict-set! p :timed-out true)
(dict-set! p :has-timeout false)
(dict-set! p :state "runnable")
(er-sched-enqueue! (get p :pid))
(set-nth! fired 0 true)))))
ks)
(nth fired 0))))
(define
er-sched-step!