def test_throttle(self):
        ns = self.Namespace()
        ns.counter = 0

        def incr():
            ns.counter += 1

        throttledIncr = _.throttle(incr, 100)
        throttledIncr()
        throttledIncr()
        throttledIncr()
        Timer(0.07, throttledIncr).start()
        Timer(0.12, throttledIncr).start()
        Timer(0.14, throttledIncr).start()
        Timer(0.19, throttledIncr).start()
        Timer(0.22, throttledIncr).start()
        Timer(0.24, throttledIncr).start()

        def checkCounter1():
            self.assertEqual(ns.counter, 1, "incr was called immediately")
            print "ASYNC: throttle. OK"

        def checkCounter2():
            self.assertEqual(ns.counter, 4, "incr was throttled")
            print "ASYNC: throttle. OK"

        _.delay(checkCounter1, 90)
        _.delay(checkCounter2, 400)
    def test_defer(self):
        ns = self.Namespace()
        ns.deferred = False

        def defertTest(bool):
            ns.deferred = bool

        _.defer(defertTest, True)

        def deferCheck():
            self.assertTrue(ns.deferred, "deferred the function")
            print "ASYNC: defer. OK"

        _.delay(deferCheck, 50)
    def test_delay(self):

        ns = self.Namespace()
        ns.delayed = False

        def func():
            ns.delayed = True

        _.delay(func, 50)

        def checkFalse():
            self.assertFalse(ns.delayed)
            print "ASYNC: delay. OK"

        def checkTrue():
            self.assertTrue(ns.delayed)
            print "ASYNC: delay. OK"

        Timer(0.03, checkFalse).start()
        Timer(0.07, checkTrue).start()
    def test_delay(self):

        ns = self.Namespace()
        ns.delayed = False

        def func():
            ns.delayed = True

        _.delay(func, 150)

        def checkFalse():
            self.assertFalse(ns.delayed)
            print("\nASYNC: delay. OK")

        def checkTrue():
            self.assertTrue(ns.delayed)
            print("\nASYNC: delay. OK")

        Timer(0.05, checkFalse).start()
        Timer(0.20, checkTrue).start()
    def test_debounce(self):
        ns = self.Namespace()
        ns.counter = 0

        def incr():
            ns.counter += 1

        debouncedIncr = _.debounce(incr, 50)
        debouncedIncr()
        debouncedIncr()
        debouncedIncr()
        Timer(0.03, debouncedIncr).start()
        Timer(0.06, debouncedIncr).start()
        Timer(0.09, debouncedIncr).start()
        Timer(0.12, debouncedIncr).start()
        Timer(0.15, debouncedIncr).start()

        def checkCounter():
            self.assertEqual(1, ns.counter, "incr was debounced")
            print "ASYNC: debounce. OK"

        _.delay(checkCounter, 220)