Use `continuation-prompt-available?` to support `actor` at prospect "toplevel".
This commit is contained in:
parent
92169d5e10
commit
d5c4b30335
|
@ -24,6 +24,7 @@
|
|||
pretty-print-actor-state
|
||||
|
||||
(for-syntax analyze-pattern)
|
||||
syndicate-actor-prompt-tag-installed?
|
||||
)
|
||||
|
||||
(require (for-syntax racket/base))
|
||||
|
@ -157,6 +158,9 @@
|
|||
|
||||
(define prompt (make-continuation-prompt-tag 'syndicate-hll))
|
||||
|
||||
(define (syndicate-actor-prompt-tag-installed?)
|
||||
(continuation-prompt-available? prompt))
|
||||
|
||||
;; (Any ... -> Nothing) -> (Any ... -> Instruction)
|
||||
(define (reply-to k)
|
||||
(lambda reply-values
|
||||
|
@ -171,6 +175,9 @@
|
|||
|
||||
;; ((Any ... -> Instruction) -> Instruction)
|
||||
(define (call-in-raw-context proc)
|
||||
(when (not (syndicate-actor-prompt-tag-installed?))
|
||||
(error 'call-in-raw-context
|
||||
"Attempt to invoke imperative Syndicate actor action outside actor context."))
|
||||
(call-with-composable-continuation
|
||||
(lambda (k) (abort-current-continuation prompt (lambda () (proc (reply-to k)))))
|
||||
prompt))
|
||||
|
@ -653,7 +660,10 @@
|
|||
;; (local-require racket/pretty)
|
||||
;; (pretty-print (syntax->datum action-fn-stx))
|
||||
|
||||
#`(spawn! '#,linkage-kind #,action-fn-stx))
|
||||
#`(let ((do-spawn (lambda () (spawn! '#,linkage-kind #,action-fn-stx))))
|
||||
(if (syndicate-actor-prompt-tag-installed?)
|
||||
(do-spawn)
|
||||
(actor-body->spawn-action do-spawn))))
|
||||
)
|
||||
|
||||
;; ;; Given a Pred, computes (and perhaps allocates):
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
(struct account (balance) #:prefab)
|
||||
(struct deposit (amount) #:prefab)
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(actor (forever #:collect [(balance 0)]
|
||||
(assert (account balance))
|
||||
(on (message (deposit $amount))
|
||||
|
@ -16,7 +14,6 @@
|
|||
(actor (forever (on (asserted (account $balance))
|
||||
(printf "Balance changed to ~a\n" balance))))
|
||||
|
||||
(until (asserted (observe (deposit _))))
|
||||
(actor (until (asserted (observe (deposit _))))
|
||||
(send! (deposit +100))
|
||||
(send! (deposit -30))
|
||||
))
|
||||
(send! (deposit -30)))
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
(struct set-box (new-value) #:transparent)
|
||||
(struct box-state (value) #:transparent)
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(actor (forever #:collect [(current-value 0)]
|
||||
(assert (box-state current-value))
|
||||
(on (message (set-box $new-value))
|
||||
|
@ -17,4 +15,3 @@
|
|||
(actor (forever (on (asserted (box-state $v))
|
||||
(log-info "client: learned that box's value is now ~v" v)
|
||||
(send! (set-box (+ v 1))))))
|
||||
))
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#lang prospect
|
||||
|
||||
(require prospect/actor)
|
||||
(require prospect/drivers/timer)
|
||||
|
||||
(spawn-timer-driver)
|
||||
|
||||
(define (sleep sec)
|
||||
(define timer-id (gensym 'sleep))
|
||||
(until (message (timer-expired timer-id _))
|
||||
#:init [(send! (set-timer timer-id (* sec 1000.0) 'relative))]))
|
||||
|
||||
(define (chain-step n)
|
||||
(printf "chain-step ~v\n" n)
|
||||
(actor (sleep 1)
|
||||
(if (< n 5)
|
||||
(chain-step (+ n 1))
|
||||
(printf "done.\n"))))
|
||||
|
||||
(chain-step 0)
|
|
@ -8,9 +8,8 @@
|
|||
(define remote-handle (tcp-address "localhost" 5999))
|
||||
(define stdin-evt (read-bytes-line-evt (current-input-port) 'any))
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
|
||||
(forever (on (message (external-event stdin-evt (list $line)) #:meta-level 1)
|
||||
(if (eof-object? line)
|
||||
(return!)
|
||||
|
@ -20,4 +19,4 @@
|
|||
(on (retracted (advertise (tcp-channel remote-handle local-handle _))) (return!))
|
||||
(on (message (tcp-channel remote-handle local-handle $bs))
|
||||
(write-bytes bs)
|
||||
(flush-output)))))
|
||||
(flush-output)))
|
||||
|
|
|
@ -29,10 +29,8 @@
|
|||
(on (message (tcp-channel them us $bs))
|
||||
(send! (says user (string-trim (bytes->string/utf-8 bs))))))))
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
(define us (tcp-listener 5999))
|
||||
(forever (assert (advertise (observe (tcp-channel _ us _))))
|
||||
(on (asserted (advertise (tcp-channel $them us _)))
|
||||
(spawn-session them us)))))
|
||||
(spawn-session them us)))
|
||||
|
|
|
@ -30,10 +30,8 @@
|
|||
(on (message (tcp-channel them us $bs) #:meta-level 1)
|
||||
(send! (says user (string-trim (bytes->string/utf-8 bs))))))))
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
(network (define us (tcp-listener 5999))
|
||||
(forever (assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
|
||||
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
|
||||
(spawn-session them us))))))
|
||||
(spawn-session them us))))
|
||||
|
|
|
@ -34,9 +34,7 @@
|
|||
(on (message (tcp-incoming-data id $bs))
|
||||
(send! (says user (string-trim (bytes->string/utf-8 bs))))))))
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
|
||||
(define us (tcp-listener 5999))
|
||||
(actor (forever (assert (advertise (observe (tcp-channel _ us _))))
|
||||
|
@ -52,4 +50,3 @@
|
|||
|
||||
(forever (on (asserted (tcp-remote-open $id))
|
||||
(spawn-session id)))
|
||||
))
|
||||
|
|
|
@ -34,11 +34,9 @@
|
|||
(send! (shutdown))
|
||||
(send! (says user input-string)))))))
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
(network (define us (tcp-listener 5999))
|
||||
(until (message (shutdown))
|
||||
(assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
|
||||
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
|
||||
(spawn-session them us))))))
|
||||
(spawn-session them us))))
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
(require prospect/actor)
|
||||
(require prospect/drivers/tcp)
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(perform-core-action! (spawn-tcp-driver))
|
||||
(spawn-tcp-driver)
|
||||
|
||||
(define server-id (tcp-listener 5999))
|
||||
(forever (assert (advertise (observe (tcp-channel _ server-id _))))
|
||||
|
@ -15,4 +13,4 @@
|
|||
(assert (advertise (tcp-channel server-id c _)))
|
||||
(on (message (tcp-channel c server-id $bs))
|
||||
(send! (tcp-channel server-id c bs))))
|
||||
(printf "Closed connection ~v\n" c))))))
|
||||
(printf "Closed connection ~v\n" c))))
|
||||
|
|
|
@ -10,10 +10,7 @@
|
|||
(struct save (file) #:prefab)
|
||||
(struct delete (name) #:prefab)
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
|
||||
(perform-core-action! (spawn-timer-driver))
|
||||
(spawn-timer-driver)
|
||||
|
||||
(actor (forever #:collect [(files (hash))]
|
||||
(on (asserted (observe (file $name _)))
|
||||
|
@ -69,5 +66,3 @@
|
|||
(printf " delete filename\n")])
|
||||
(sleep 0.1)
|
||||
(print-prompt)))))
|
||||
|
||||
))
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
(struct echo-req (body) #:prefab)
|
||||
(struct echo-resp (body) #:prefab)
|
||||
|
||||
(actor-body->spawn-action
|
||||
(lambda ()
|
||||
(actor (forever #:collect [(count 0)]
|
||||
(on (message (echo-req $body))
|
||||
(send! (echo-resp body))
|
||||
|
@ -15,9 +13,8 @@
|
|||
(actor (forever (on (message (echo-resp $body))
|
||||
(printf "Received: ~v\n" body))))
|
||||
|
||||
(until (asserted (observe (echo-req _))))
|
||||
(actor (until (asserted (observe (echo-req _))))
|
||||
(until (asserted (observe (echo-resp _))))
|
||||
(send! (echo-req 0))
|
||||
(send! (echo-req 1))
|
||||
(send! (echo-req 2))
|
||||
))
|
||||
(send! (echo-req 2)))
|
||||
|
|
Loading…
Reference in New Issue