Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
async def await_forever():
    print("Awaiting forever")
    future = netius.build_future()
    thread = threading.Thread(target=set,
                              args=(future, ),
                              kwargs=dict(raise_e=True))
    thread.start()
    return await future
Esempio n. 4
0
def await_forever():
    print("Awaiting forever")
    future = netius.build_future()
    thread = threading.Thread(target=set,
                              args=(future, ),
                              kwargs=dict(raise_e=True))
    thread.start()
    for value in future:
        yield value
Esempio n. 5
0
def await_forever():
    print("Awaiting forever")
    future = netius.build_future()
    thread = threading.Thread(
        target = set,
        args = (future,),
        kwargs = dict(raise_e = True)
    )
    thread.start()
    for value in future: yield value
Esempio n. 6
0
def await_forever():
    print("Awaiting forever")
    future = netius.build_future()
    thread = threading.Thread(
        target = set,
        args = (future,),
        kwargs = dict(raise_e = True)
    )
    thread.start()
    result = yield from future
    return result
Esempio n. 7
0
def print_sum(x, y):
    future = netius.build_future()
    for value in compute(future, x, y):
        yield value
    result = future.result()
    print("%s + %s = %s" % (x, y, result))