Allow sending messages to put to-actor as an actual actor instance.
[8sync.git] / 8sync / actors.scm
index a069a7182a4ae74052a62874cf85266424eec654..6d17e0597d9bab86bdaf86b6f85bd34fbd7179a5 100644 (file)
@@ -43,6 +43,8 @@
             actor-id
             actor-message-handler
 
+            *current-actor*
+
             ;;; Commenting out the <address> type for now;
             ;;; it may be back when we have better serializers
             ;; <address>
@@ -56,8 +58,6 @@
 
             actor-init! actor-cleanup!
 
-            actor-alive?
-
             build-actions
 
             define-actor
 ;; This is the internal, generalized message sending method.
 ;; Users shouldn't use it!  Use the <-foo forms instead.
 
-(define-inlinable (%<- wants-reply from-actor to action args message-id in-reply-to)
+(define (%<- wants-reply from-actor to action args message-id in-reply-to)
   ;; Okay, we need to deal with message ids.
   ;; Could we get rid of them? :\
   ;; It seems if we can use eq? and have messages be immutable then
      'TODO)
     ;; A message sent to nobody goes nowhere.
     ;; TODO: Should we display a warning here, probably?
-    (#f #f)))
+    (#f #f)
+    ;; We shouldn't technically be passing in actors but rather their
+    ;; addresses, but often actors want to message themselves and
+    ;; this makes that slightly easier.
+    ((? (lambda (x) (is-a? x <actor>)) actor)
+     (%<- wants-reply from-actor (actor-id actor) action
+          args message-id in-reply-to))))
 
 (define (<- to action . args)
   (define from-actor (*current-actor*))
@@ -670,14 +676,3 @@ its '*cleanup* action handler."
   (*actor-prompt* #f)
   (actor-cleanup! actor))
 
-;; From a patch I sent to Fibers...
-(define (condition-signalled? cvar)
-  "Return @code{#t} if @var{cvar} has already been signalled.
-
-In general you will want to use @code{wait} or @code{wait-operation} to
-wait on a condition.  However, sometimes it is useful to see whether or
-not a condition has already been signalled without blocking."
-  (atomic-box-ref ((@@ (fibers conditions) condition-signalled?) cvar)))
-
-(define (actor-alive? actor)
-  (condition-signalled? (address-dead? (actor-id actor))))