def testSequentialCalls(self): log = [] EventLoop.call(log.append, 1) EventLoop.call(log.append, 2) EventLoop.call(log.append, 3) EventLoop.call(log.append, 4) class IdleTimer(trellis.Component): trellis.attrs( idle_timeout=20, busy=False, ) idle_for = trellis.maintain( lambda self: self.idle_for.begins_with(not self.busy), initially=NOT_YET) @trellis.maintain # XXX should be perform def alarm(self): if self.idle_for[self.idle_timeout] and EventLoop.running: log.append(5) EventLoop.stop() it = IdleTimer() EventLoop.run() self.assertEqual(log, [1, 2, 3, 4, 5])
def testSequentialCalls(self): log = [] EventLoop.call(log.append, 1) EventLoop.call(log.append, 2) EventLoop.call(log.append, 3) EventLoop.call(log.append, 4) class IdleTimer(trellis.Component): trellis.attrs( idle_timeout = 20, busy = False, ) idle_for = trellis.maintain( lambda self: self.idle_for.begins_with(not self.busy), initially=NOT_YET ) trellis.maintain() # XXX should be perform def alarm(self): if self.idle_for[self.idle_timeout] and EventLoop.running: log.append(5) EventLoop.stop() it = IdleTimer() EventLoop.run() self.assertEqual(log, [1,2,3,4,5])
def testSequentialCalls(self): log = [] EventLoop.call(log.append, 1) EventLoop.call(log.append, 2) EventLoop.call(log.append, 3) EventLoop.call(log.append, 4) EventLoop.call(EventLoop.stop) EventLoop.run() self.assertEqual(log, [1,2,3,4])
def testSequentialCalls(self): log = [] EventLoop.call(log.append, 1) EventLoop.call(log.append, 2) EventLoop.call(log.append, 3) EventLoop.call(log.append, 4) event = Time[0.00001] def c(): if event: # events aren't EventLoop.call(EventLoop.stop) c = trellis.Cell(c) c.value # This will loop indefinitely, if sub-millisecond events aren't # rounded up to the next millisecond. EventLoop.run() self.frame.Destroy() self.assertEqual(log, [1, 2, 3, 4])
def testSequentialCalls(self): log = [] EventLoop.call(log.append, 1) EventLoop.call(log.append, 2) EventLoop.call(log.append, 3) EventLoop.call(log.append, 4) event = Time[0.00001] def c(): if event: # events aren't EventLoop.call(EventLoop.stop) c = trellis.Cell(c) c.value # This will loop indefinitely, if sub-millisecond events aren't # rounded up to the next millisecond. EventLoop.run() self.frame.Destroy() self.assertEqual(log, [1, 2, 3, 4])
def testNoTodoRollbackIntoTask(self): class CV(trellis.Component): v = trellis.attr(False) s = trellis.make(trellis.Set, name="s") @trellis.maintain def maintain(self): if self.v: self.s.add(1) else: self.s.discard(1) @trellis.perform def perform(s): self.assertEqual(s.v, True) @activity.TaskCell def task(): cv = CV() cv.v = True yield activity.Pause EventLoop.run()
def testNoTodoRollbackIntoTask(self): class CV(trellis.Component): v = trellis.attr(False) s = trellis.make(trellis.Set, name='s') @trellis.maintain def maintain(self): if self.v: self.s.add(1) else: self.s.discard(1) @trellis.perform def perform(s): self.assertEqual(s.v, True) @activity.TaskCell def task(): cv = CV() cv.v = True yield activity.Pause EventLoop.run()