File: _async_common.py

package info (click to toggle)
python-ijson 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 668 kB
  • sloc: python: 2,687; ansic: 1,776; sh: 4; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 479 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- coding:utf-8 -*-

import asyncio
import contextlib


def _aiorun(f):
    with contextlib.closing(asyncio.new_event_loop()) as loop:
        loop.run_until_complete(f)


def _get_all(reader):
    def get_all(routine, json_content, *args, **kwargs):
        events = []
        async def run():
            async for event in routine(reader(json_content), *args, **kwargs):
                events.append(event)
        _aiorun(run())
        return events
    return get_all