init id-cookie))
-(define (self-destruct actor)
- "Remove an actor from the hive."
+(define* (self-destruct actor #:key (clean-up #t))
+ "Remove an actor from the hive.
+
+Unless #:clean-up is set to #f, this will first have the actor handle
+its '*clean-up* action handler."
+ (when clean-up
+ (<-wait actor (actor-id actor) '*clean-up*))
(hash-remove! (hive-actor-registry (actor-hive actor))
(actor-id actor)))
;;; 8sync bootstrap utilities
;;; =========================
-(define* (run-hive hive initial-tasks)
+(define* (run-hive hive initial-tasks
+ #:key (clean-up #t))
"Start up an agenda and run HIVE in it with INITIAL-TASKS."
(dynamic-wind
(const #f)
(start-agenda agenda)))
;; Run clean-up
(lambda ()
- (run-hive-clean-up hive))))
+ (when clean-up
+ (run-hive-clean-up hive)))))
(define (run-hive-clean-up hive)
(let ((queue (list->q (list (bootstrap-message hive (actor-id hive)
customer> Whaaaaat? I can't believe I got voice mail!\n"
displayed-text))))
-(define-simple-actor <foo>
+\f
+;;; Cleanup tests
+
+(define-simple-actor <cleanly>
(*clean-up* test-call-clean-up))
(define (test-call-clean-up actor message)
(with-fresh-speaker
(let ((hive (make-hive)))
- (hive-create-actor hive <foo>)
+ (hive-create-actor hive <cleanly>)
(run-hive hive '()))
(test-equal '("Hey, I'm cleanin' up here!\n")
(get-spoken)))
+;; won't work if we turn off #:clean-up though
+
+(with-fresh-speaker
+ (let ((hive (make-hive)))
+ (hive-create-actor hive <cleanly>)
+ (run-hive hive '() #:clean-up #f))
+ (test-equal '("Hey, I'm cleanin' up here!\n")
+ (get-spoken)))
+
+;; The exploder self-destructs, even though run-hive has clean-up
+;; disabled, because it cleans up on self-destruct.
+
+(with-fresh-speaker
+ (let ((hive (make-hive)))
+ (define exploder (hive-create-actor hive <exploder>))
+ (run-hive hive (list (bootstrap-message hive exploder 'explode))
+ #:clean-up #f))
+ (get-spoken))
+
+
(test-end "test-actors")
(test-exit)