def recv(self, atom, args): from typhon.objects.collections.maps import EMPTY_MAP if atom is FROMNOW_1: duration = promoteToDouble(args[0]) p, r = makePromise() vat = currentVat.get() uv_timer = ruv.alloc_timer(vat.uv_loop) # Stash the resolver. ruv.stashTimer(uv_timer, (vat, r)) # repeat of 0 means "don't repeat" ruv.timerStart(uv_timer, resolveTimer, int(duration * 1000), 0) assert ruv.isActive(uv_timer), "Timer isn't active!?" return p if atom is TRIAL_1: obj = args[0] then = time.time() obj.call(u"run", []) now = time.time() # We can't give the value up immediately, due to determinism # requirements. Instead, provide it as a promise which will be # available on subsequent turns. rv = DoubleObject(now - then) p, r = makePromise() vat = currentVat.get() vat.sendOnly(r, RESOLVE_1, [rv], EMPTY_MAP) return p raise Refused(self, atom, args)
def recv(self, atom, args): from typhon.objects.collections.maps import EMPTY_MAP if atom is UNSAFENOW_0: return DoubleObject(time.time()) if atom is FROMNOW_1: duration = promoteToDouble(args[0]) p, r = makePromise() vat = currentVat.get() uv_timer = ruv.alloc_timer(vat.uv_loop) # Stash the resolver. ruv.stashTimer(uv_timer, (vat, r)) # repeat of 0 means "don't repeat" ruv.timerStart(uv_timer, resolveTimer, int(duration * 1000), 0) assert ruv.isActive(uv_timer), "Timer isn't active!?" return p if atom is SENDTIMESTAMP_1: now = time.time() vat = currentVat.get() return vat.send(args[0], RUN_1, [DoubleObject(now)], EMPTY_MAP) raise Refused(self, atom, args)
def testPromoteToDoublePromise(self): with scopedVat(testingVat()): p = makeNear(DoubleObject(4.2)) self.assertAlmostEqual(promoteToDouble(p), 4.2)