def test_parked_buffered(self): d = Deferred() ch = Channel(1) var = {"count": 0} def inc(ok): var["count"] += 1 put_then_callback(ch, 42, inc) put_then_callback(ch, 42, inc) def taken(value): def checking(): # yield control so that the second put can proceed yield None self.assertEqual(var["count"], 2, "second (buffered) put succeeds") d.callback(CLOSED) go(checking) take_then_callback(ch, taken) return d
def test_parked_buffered(self): d = Deferred() ch = Channel(1) var = {"count": 0} def inc(ok): var["count"] += 1 put_then_callback(ch, 42, inc) put_then_callback(ch, 42, inc) def taken(value): def checking(): # yield control so that the second put can proceed # XXX: @inlineCallbacks seems to resume the generator # in the same tick if the result is immediately # available (not a deferred, or an already resolved # deferred), so we need to force next tick by "sleep". # I think this is bad behavior from @inlineCallbacks. yield sleep(0) self.assertEqual(var["count"], 2, "second (buffered) put succeeds") d.callback(CLOSED) go(checking) take_then_callback(ch, taken) return d