Example #1
0
    def queue_ready_prefix(queue, now=None):
        """Return the elements of *queue* that are due.

        *queue* is a sorted list of :class:`TimeDueOrdinal` instances.
        *now* is the timestamp, and defaults to :func:`coapy.clock`.
        Elements are due when :attr:`time_due` <= *now*.
        """

        if now is None:
            now = coapy.clock()
        ub = 0
        while ub < len(queue) and (queue[ub].time_due <= now):
            ub += 1
        return list(queue[:ub])
Example #2
0
    def queue_ready_prefix(queue, now=None):
        """Return the elements of *queue* that are due.

        *queue* is a sorted list of :class:`TimeDueOrdinal` instances.
        *now* is the timestamp, and defaults to :func:`coapy.clock`.
        Elements are due when :attr:`time_due` <= *now*.
        """

        if now is None:
            now = coapy.clock()
        ub = 0
        while ub < len(queue) and (queue[ub].time_due <= now):
            ub += 1
        return list(queue[:ub])
Example #3
0
 def testBasic(self):
     now = coapy.clock()
     td1 = TimeDueOrdinal(time_due=now)
     td0 = TimeDueOrdinal(time_due=now - 1)
     self.assertTrue(td0 < td1)
     td2 = TimeDueOrdinal(time_due=now + 1)
     queue = []
     td2.queue_insert(queue)
     td1.queue_insert(queue)
     td0.queue_insert(queue)
     self.assertTrue(queue[0] is td0)
     self.assertTrue(queue[1] is td1)
     self.assertTrue(queue[2] is td2)
     self.assertEqual([],
                      TimeDueOrdinal.queue_ready_prefix(
                          queue, td0.time_due - 1))
     self.assertEqual([td0],
                      TimeDueOrdinal.queue_ready_prefix(
                          queue, td0.time_due))
     self.assertEqual(
         queue, TimeDueOrdinal.queue_ready_prefix(queue, td2.time_due + 1))
Example #4
0
 def testClock(self):
     cv = coapy.clock()
     self.assertTrue(cv > coapy.clock.epoch)