facet-on-end-of-turn!

This commit is contained in:
Tony Garnock-Jones 2021-06-09 23:04:58 +02:00
parent cce81dc104
commit 52362a9183
2 changed files with 15 additions and 3 deletions

View File

@ -24,6 +24,7 @@
facet-parent facet-parent
facet-live? facet-live?
facet-inert? facet-inert?
facet-on-end-of-turn!
facet-on-stop! facet-on-stop!
facet-prevent-inert-check! facet-prevent-inert-check!
*dead-facet* *dead-facet*
@ -96,6 +97,7 @@
parent parent
children children
outbound outbound
[end-of-turn-actions #:mutable]
[shutdown-actions #:mutable] [shutdown-actions #:mutable]
[live? #:mutable] [live? #:mutable]
[inert-check-preventers #:mutable]) [inert-check-preventers #:mutable])
@ -144,6 +146,7 @@
(make-hasheq) (make-hasheq)
(make-hash) (make-hash)
'() '()
'()
#f #f
0)) 0))
@ -212,12 +215,16 @@
(make-hasheq) (make-hasheq)
initial-assertions initial-assertions
'() '()
'()
#t #t
0)) 0))
(when parent (when parent
(hash-set! (facet-children parent) f #t)) (hash-set! (facet-children parent) f #t))
f) f)
(define (facet-on-end-of-turn! f action)
(set-facet-end-of-turn-actions! f (cons action (facet-end-of-turn-actions f))))
(define (facet-on-stop! f action) (define (facet-on-stop! f action)
(set-facet-shutdown-actions! f (cons action (facet-shutdown-actions f)))) (set-facet-shutdown-actions! f (cons action (facet-shutdown-actions f))))
@ -277,7 +284,13 @@
(lambda (turn) (lambda (turn)
(actor-terminate! turn ac e))))]) (actor-terminate! turn ac e))))])
(action turn) (action turn)
(dataflow-repair-damage! (actor-dataflow ac) (lambda (action) (action turn))) (let loop ()
(dataflow-repair-damage! (actor-dataflow ac) (lambda (action) (action turn)))
(define pending (reverse (facet-end-of-turn-actions f)))
(when (pair? pending)
(set-facet-end-of-turn-actions! f '())
(for [(action (in-list pending))] (action turn))
(loop)))
(for [((ff qq) (in-hash (turn-queues turn)))] (for [((ff qq) (in-hash (turn-queues turn)))]
(queue-task! (actor-engine (facet-actor ff)) (queue-task! (actor-engine (facet-actor ff))
(lambda () (lambda ()

View File

@ -96,8 +96,7 @@
(stop-facet this-facet expr ...)) (stop-facet this-facet expr ...))
(define-syntax-rule (on-start expr ...) (define-syntax-rule (on-start expr ...)
;; TODO: delay to end of turn (?) (facet-on-end-of-turn! this-facet (action () expr ...)))
(begin expr ...))
(define-syntax-rule (on-stop expr ...) (define-syntax-rule (on-stop expr ...)
(facet-on-stop! this-facet (action () expr ...))) (facet-on-stop! this-facet (action () expr ...)))