def test_basic(self): loop = netius.get_loop(asyncio = False) self.assertNotEqual(loop, None) self.assertEqual(isinstance(loop, netius.Base), True) future = netius.build_future(compat = False, asyncio = False) self.assertNotEqual(future, None) self.assertEqual(isinstance(future, netius.Future), True) self.assertNotEqual(future._loop, None) self.assertEqual(isinstance(future._loop, netius.Base), True) previous = loop loop = netius.get_loop(_compat = True) self.assertNotEqual(loop, None) self.assertEqual(isinstance(loop, netius.BaseLoop), True) self.assertEqual(isinstance(loop, netius.CompatLoop), True) self.assertEqual(loop, previous._compat) self.assertEqual(loop._loop_ref(), previous) loop = netius.get_loop(asyncio = True) self.assertNotEqual(loop, None) if netius.is_asynclib(): self.assertEqual(isinstance(loop, netius.BaseLoop), True) self.assertEqual(isinstance(loop, netius.CompatLoop), True) else: self.assertEqual(isinstance(loop, netius.Base), True)
def test_basic(self): loop = netius.get_loop(asyncio=False) self.assertNotEqual(loop, None) self.assertEqual(isinstance(loop, netius.Base), True) future = netius.build_future(compat=False, asyncio=False) self.assertNotEqual(future, None) self.assertEqual(isinstance(future, netius.Future), True) self.assertNotEqual(future._loop, None) self.assertEqual(isinstance(future._loop, netius.Base), True) previous = loop loop = netius.get_loop(_compat=True) self.assertNotEqual(loop, None) self.assertEqual(isinstance(loop, netius.BaseLoop), True) self.assertEqual(isinstance(loop, netius.CompatLoop), True) self.assertEqual(loop, previous._compat) self.assertEqual(loop._loop_ref(), previous) loop = netius.get_loop(asyncio=True) self.assertNotEqual(loop, None) if netius.is_asynclib(): self.assertEqual(isinstance(loop, netius.BaseLoop), True) self.assertEqual(isinstance(loop, netius.CompatLoop), True) else: self.assertEqual(isinstance(loop, netius.Base), True)
""" The revision number of the module """ __date__ = "$LastChangedDate$" """ The last change date of the module """ __copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda." """ The copyright for the module """ __license__ = "Apache License, Version 2.0" """ The license for the module """ import netius async def compute(x, y): return (await _compute(x, y)) @netius.coroutine def _compute(x, y): print("Compute %s + %s ..." % (x, y)) yield from netius.sleep(1.0) return x + y loop = netius.get_loop(_compat=True) result = loop.run_until_complete(compute(1, 2)) loop.close() print(result)
__revision__ = "$LastChangedRevision$" """ The revision number of the module """ __date__ = "$LastChangedDate$" """ The last change date of the module """ __copyright__ = "Copyright (c) 2008-2017 Hive Solutions Lda." """ The copyright for the module """ __license__ = "Apache License, Version 2.0" """ The license for the module """ import netius @netius.coroutine def compute(future, x, y): print("Compute %s + %s ..." % (x, y)) for value in netius.sleep(1.0): yield value future.set_result(x + y) @netius.coroutine def print_sum(x, y): future = netius.Future() for value in compute(future, x, y): yield value result = future.result() print("%s + %s = %s" % (x, y, result)) loop = netius.get_loop() loop.run_until_complete(print_sum, args = (1, 2)) loop.close()
__author__ = "João Magalhães <*****@*****.**>" """ The author(s) of the module """ __version__ = "1.0.0" """ The version of the module """ __revision__ = "$LastChangedRevision$" """ The revision number of the module """ __date__ = "$LastChangedDate$" """ The last change date of the module """ __copyright__ = "Copyright (c) 2008-2019 Hive Solutions Lda." """ The copyright for the module """ __license__ = "Apache License, Version 2.0" """ The license for the module """ import netius async def compute(x, y): print("Compute %s + %s ..." % (x, y)) await netius.sleep(1.0) return x + y loop = netius.get_loop(_compat = True) result = loop.run_until_complete(compute(1, 2)) loop.close() print(result)