Browse Source

Rename syncp to sync/pr

add-remove-to-filo-queue
Christopher Lemmer Webber 5 years ago
parent
commit
2bbc24e510
No known key found for this signature in database
GPG Key ID: 4BC025925FF8F4D3
  1. 6
      goblins/actor-lib/sleep-pr.rkt
  2. 20
      goblins/actor-lib/sync-pr.rkt

6
goblins/actor-lib/sleep-pr.rkt

@ -1,10 +1,10 @@
#lang racket/base #lang racket/base
(require "syncp.rkt") (require "sync-pr.rkt")
(provide sleep/pr) (provide sleep/pr)
(define (sleep/pr secs) (define (sleep/pr secs)
(syncp (alarm-evt (+ (current-inexact-milliseconds) (sync/pr (alarm-evt (+ (current-inexact-milliseconds)
(* secs 1000))))) (* secs 1000)))))

20
goblins/actor-lib/syncp.rkt → goblins/actor-lib/sync-pr.rkt

@ -1,6 +1,6 @@
#lang racket/base #lang racket/base
;; syncp and syncp* produce promises that are fulfilled upon the ;; sync/pr and sync/pr* produce promises that are fulfilled upon the
;; completion of a synchronizable event. ;; completion of a synchronizable event.
;; They set up a separate thread which watches for synchronization. ;; They set up a separate thread which watches for synchronization.
@ -8,11 +8,11 @@
(submod "../core.rkt" np-extern) (submod "../core.rkt" np-extern)
racket/match) racket/match)
(provide syncp* syncp) (provide sync/pr* sync/pr)
;; This one is also cancelable, but it returns two values to its continuation. ;; This one is also cancelable, but it returns two values to its continuation.
;; It only accepts one argument, so you'll have to choice-evt yourself if need be. ;; It only accepts one argument, so you'll have to choice-evt yourself if need be.
(define (syncp* evt #:timeout [timeout #f]) (define (sync/pr* evt #:timeout [timeout #f])
(define-values (promise resolver) (define-values (promise resolver)
(spawn-promise-values)) (spawn-promise-values))
(define cancel-semaphore (make-semaphore)) (define cancel-semaphore (make-semaphore))
@ -34,15 +34,15 @@
(values promise cancel!)) (values promise cancel!))
;; No way to cancel, just returns the promise ;; No way to cancel, just returns the promise
(define (syncp #:timeout [timeout #f] . evts) (define (sync/pr #:timeout [timeout #f] . evts)
(match evts (match evts
[(list evt) [(list evt)
(define-values (promise _cancel) (define-values (promise _cancel)
(syncp* evt #:timeout timeout)) (sync/pr* evt #:timeout timeout))
promise] promise]
[evts [evts
(define-values (promise _cancel) (define-values (promise _cancel)
(syncp* (apply choice-evt evts) #:timeout timeout)) (sync/pr* (apply choice-evt evts) #:timeout timeout))
promise])) promise]))
(module+ test (module+ test
@ -54,7 +54,7 @@
(let ([result-ch (make-channel)] (let ([result-ch (make-channel)]
[incoming-ch (make-channel)]) [incoming-ch (make-channel)])
(vat-run (vat-run
(on (syncp incoming-ch) (on (sync/pr incoming-ch)
(lambda (val) (lambda (val)
(channel-put result-ch `(success ,val))) (channel-put result-ch `(success ,val)))
#:catch #:catch
@ -62,7 +62,7 @@
(channel-put result-ch `(failure ,err))))) (channel-put result-ch `(failure ,err)))))
(channel-put incoming-ch 'hello-there) (channel-put incoming-ch 'hello-there)
(test-equal? (test-equal?
"syncp simple success case" "sync/pr simple success case"
(sync/timeout 1 result-ch) (sync/timeout 1 result-ch)
'(success (hello-there)))) '(success (hello-there))))
@ -71,7 +71,7 @@
(define cancel (define cancel
(vat-run (vat-run
(define-values (p cancel) (define-values (p cancel)
(syncp* incoming-ch)) (sync/pr* incoming-ch))
(on p (on p
(lambda (val) (lambda (val)
(channel-put result-ch `(success ,val))) (channel-put result-ch `(success ,val)))
@ -81,6 +81,6 @@
cancel)) cancel))
(cancel) (cancel)
(test-equal? (test-equal?
"syncp* canceled" "sync/pr* canceled"
(sync/timeout 1 result-ch) (sync/timeout 1 result-ch)
'(failure canceled)))) '(failure canceled))))
Loading…
Cancel
Save