File: async_wrapper.py

package info (click to toggle)
python-adb-shell 0.4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 760 kB
  • sloc: python: 3,860; makefile: 191; sh: 124
file content (24 lines) | stat: -rw-r--r-- 485 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import asyncio
import warnings



def _await(coro):
    """Create a new event loop, run the coroutine, then close the event loop."""
    loop = asyncio.new_event_loop()

    with warnings.catch_warnings(record=True) as warns:
        ret = loop.run_until_complete(coro)
        loop.close()

        if warns:
            raise RuntimeError

        return ret


def awaiter(func):
    def sync_func(*args, **kwargs):
        return _await(func(*args, **kwargs))

    return sync_func