Browse Source

Add ensure-same which takes in refrs and checks they are eq?

This is to be used to take a number of refrs to actors and verify that
they are all the exat same object. It will error if they are not,
otherwise it returns one of the refrs.
merge-requests/25/head
Jessica Tallon 4 years ago
parent
commit
59fa92e353
  1. 54
      goblins/actor-lib/joiners.rkt

54
goblins/actor-lib/joiners.rkt

@ -17,9 +17,12 @@
(provide all-of all-of* any-of)
(require "../core.rkt"
"../ocapn/captp.rkt"
"../ocapn/structs-urls.rkt"
"cell.rkt"
"methods.rkt"
racket/set)
racket/set
racket/match)
(define (all-of* promises)
(define-cell waiting
@ -89,9 +92,25 @@
($ waiting new-waiting)])))))
join-promise)
(define (ensure-same . refrs-vows)
(define (all-eq? items)
(match items
[(list item) item]
[(list 1st 2nd rest ...)
(if (eq? 1st 2nd)
(all-eq? (cons 2nd rest))
(error "items given do not resolve to the same"))]))
(on (all-of* refrs-vows)
(lambda (refrs)
(pk 'refrs refrs)
(all-eq? refrs))
#:promise? #t))
(module+ test
(require "../vat.rkt"
rackunit
racket/async-channel
racket/match)
(define a-vat
@ -139,4 +158,35 @@
(test-true
"any-of breaks promise if no fulfilled promises are given"
(match (run-joiner-get-result any-of 7 9 11)
[(vector 'broken _err) #t])))
[(vector 'broken _err) #t]))
(define b-vat (make-vat))
(define ((^my-actor _bcom))
'hello)
(define my-actor (b-vat 'spawn ^my-actor))
(define my-actor-1 my-actor)
(define my-actor-2 my-actor)
(define another-actor (a-vat 'spawn ^my-actor))
(define result-ch (make-async-channel))
(a-vat 'run
(lambda ()
(on (ensure-same my-actor my-actor-1 my-actor-2)
(lambda (result)
(async-channel-put result-ch `(result ,result))))))
(check-equal?
(sync/timeout 1 result-ch)
(list 'result my-actor))
(a-vat 'run
(lambda _
(on (ensure-same my-actor my-actor-1 another-actor)
#:catch
(lambda (err)
(async-channel-put result-ch `(err ,(exn-message err)))))))
(check-equal?
(sync/timeout 1 result-ch)
(list 'err "items given do not resolve to the same")))

Loading…
Cancel
Save