async def main(): from_ch = chan() a_ch, b_ch = chan(), chan() p = c.pub(from_ch, lambda x: x[0], lambda x: None if x == 'a' else 2) p.sub('a', a_ch) p.sub('b', b_ch) await from_ch.put('a1') await from_ch.put('a2') await asyncio.sleep(0.1) self.assertIs(from_ch.offer('a fail'), False) self.assertEqual(await a_ch.get(), 'a1') self.assertEqual(await a_ch.get(), 'a2') await asyncio.sleep(0.1) self.assertIsNone(a_ch.poll()) await from_ch.put('b1') await from_ch.put('b2') await from_ch.put('b3') await from_ch.put('b4') await asyncio.sleep(0.1) self.assertIs(from_ch.offer('b fail'), False) self.assertEqual(await b_ch.get(), 'b1') self.assertEqual(await b_ch.get(), 'b2') self.assertEqual(await b_ch.get(), 'b3') self.assertEqual(await b_ch.get(), 'b4') await asyncio.sleep(0.1) self.assertIsNone(b_ch.poll())
async def main(): from_ch, to_ch = chan(1), chan() p = c.pub(from_ch, xf.identity) p.sub('a', to_ch) p.unsub('b', chan()) await from_ch.put('a') self.assertEqual(await to_ch.get(), 'a')
async def main(): from_ch, close_ch, open_ch = chan(1), chan(1), chan(1) p = c.pub(from_ch, xf.identity) p.sub('close', close_ch) p.sub('open', open_ch, close=False) from_ch.close() await asyncio.sleep(0.1) self.assertIs(await close_ch.put('fail'), False) self.assertIs(await open_ch.put('success'), True)
async def main(): from_ch, a_ch, b_ch = chan(2), chan(), chan() p = c.pub(from_ch, lambda x: x[0]) p.sub('a', a_ch) p.sub('b', b_ch) p.unsub_all() await from_ch.put('apple') await from_ch.put('bat') await asyncio.sleep(0.1) self.assertIsNone(from_ch.poll()) self.assertIsNone(a_ch.poll()) self.assertIsNone(b_ch.poll()) p.sub('a', a_ch) await from_ch.put('air') self.assertEqual(await a_ch.get(), 'air')
async def main(): from_ch = chan(1) a1_ch, a2_ch, b1_ch, b2_ch = chan(), chan(), chan(), chan() p = c.pub(from_ch, lambda x: x[0]) p.sub('a', a1_ch) p.sub('a', a2_ch) p.sub('b', b1_ch) p.sub('b', b2_ch) await from_ch.put('apple') self.assertEqual(await a1_ch.get(), 'apple') self.assertEqual(await a2_ch.get(), 'apple') await from_ch.put('bat') self.assertEqual(await b1_ch.get(), 'bat') self.assertEqual(await b2_ch.get(), 'bat') await from_ch.put('ant') self.assertEqual(await a1_ch.get(), 'ant') self.assertEqual(await a2_ch.get(), 'ant') await from_ch.put('bear') self.assertEqual(await b1_ch.get(), 'bear') self.assertEqual(await b2_ch.get(), 'bear')