# Copyright 2008 Kevin Reid under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") def makeProxy :DeepFrozen := /** Make an eventual ref which stores its messages in a buffer, and delivers all messages so far (but not future messages) to another ref on command. Originally written for orchestrating tests of eventual protocols. */ def makeDelayingRef(resolved :boolean) implements ExitViaHere, DeepFrozen { # future ideas: allow promise->far transition while still buffering; allow a user-supplied buffer def buffer := [].diverge() def delayingRefHandler { method handleSend(verb, args) :any { def [p, r] := Ref.promise() buffer.push([verb, args, r]) p } method handleSendOnly(verb, args) { # XXX we should propagate sendOnlyness since it is visible to the target delayingRefHandler.handleSend(verb, args) } method handleOptSealedDispatch(brand) { null } } def delayingRefResolver { to resolveSoFar(target) { for [verb, args, resolver] in buffer.removeRun(0) { resolver.resolve(E.send(target, verb, args)) } } } return [makeProxy(delayingRefHandler, (def p; p), resolved), delayingRefResolver] }