def __init__(self, handler, resolutionBox): if not isSettled(handler): raise userError(u"Proxy handler not settled: " + handler.toString()) self.handler = handler self.resolutionBox = resolutionBox self.committed = False
def makeProxy(handler, resolutionBox, resolved): if not isSettled(handler): raise userError(u"Proxy handler not settled") if unwrapBool(resolved): return FarRef(handler, resolutionBox) else: return RemotePromise(handler, resolutionBox)
def recv(self, atom, args): if atom is BROKEN_1: return self.broken(args[0]) if atom is FULFILLMENT_1: return self.fulfillment(args[0]) if atom is ISBROKEN_1: return wrapBool(self.isBroken(args[0])) if atom is ISDEEPFROZEN_1: return wrapBool(self.isDeepFrozen(args[0])) if atom is ISEVENTUAL_1: return wrapBool(self.isEventual(args[0])) if atom is ISNEAR_1: return wrapBool(self.isNear(args[0])) if atom is ISFAR_1: return wrapBool(self.isFar(args[0])) if atom is ISRESOLVED_1: return wrapBool(isResolved(args[0])) if atom is ISSELFISH_1: return wrapBool(self.isSelfish(args[0])) if atom is ISSELFLESS_1: return wrapBool(self.isSelfless(args[0])) if atom is ISSETTLED_1: from typhon.objects.equality import isSettled return wrapBool(isSettled(args[0])) if atom is MAKEPROXY_3: from typhon.objects.proxy import makeProxy return makeProxy(args[0], args[1], args[2]) if atom is OPTPROBLEM_1: ref = args[0] if isinstance(ref, Promise): return ref.optProblem() return NullObject if atom is PROMISE_0: return self.promise() # Inlined for name clash reasons. if atom is STATE_1: o = args[0] if isinstance(o, Promise): s = o.state() else: s = NEAR return StrObject(s.repr) if atom is WHENBROKEN_2: return self.whenBroken(args[0], args[1]) if atom is WHENRESOLVED_2: return self.whenResolved(args[0], args[1]) if atom is WHENRESOLVEDONLY_2: return self.whenResolvedOnly(args[0], args[1]) raise Refused(self, atom, args)
def testPromiseResolved(self): with scopedVat(testingVat()): p, r = makePromise() r.resolve(IntObject(42)) self.assertTrue(isSettled(p))
def testPromise(self): with scopedVat(testingVat()): p, r = makePromise() self.assertFalse(isSettled(p))
def testNaN(self): d = DoubleObject(float("nan")) self.assertTrue(isSettled(d))
def testInt(self): i = IntObject(42) self.assertTrue(isSettled(i))