Exemple #1
0
 def get_completions_async(self, document, complete_event):
     """
     Asynchronous generator of completions.
     This yields both Future and Completion objects.
     """
     return generator_to_async_generator(
         lambda: self.completer.get_completions(document, complete_event))
 def get_completions_async(self, document, complete_event):
     """
     Asynchronous generator of completions.
     This yields both Future and Completion objects.
     """
     return generator_to_async_generator(
         lambda: self.completer.get_completions(document, complete_event))
Exemple #3
0
 async def get_completions_async(
         self, document: Document, complete_event: CompleteEvent) -> AsyncGenerator[Completion, None]:
     """
     Asynchronous generator of completions.
     """
     async for completion in generator_to_async_generator(
             lambda: self.completer.get_completions(document, complete_event)):
         yield completion
 async def get_completions_async(
         self, document: Document, complete_event: CompleteEvent) -> AsyncGenerator[Completion, None]:
     """
     Asynchronous generator of completions.
     """
     async for completion in generator_to_async_generator(
             lambda: self.completer.get_completions(document, complete_event)):
         yield completion
def test_generator_to_async_generator():
    """
    Test conversion of sync to asycn generator.
    This should run the synchronous parts in a background thread.
    """
    async_gen = generator_to_async_generator(_sync_generator)

    items = []
    async def consume_async_generator():
        async for item in async_gen:
            items.append(item)

    # Run the event loop until all items are collected.
    get_event_loop().run_until_complete(consume_async_generator())
    assert items == [1, 10]
Exemple #6
0
def test_generator_to_async_generator():
    """
    Test conversion of sync to asycn generator.
    This should run the synchronous parts in a background thread.
    """
    async_gen = generator_to_async_generator(_sync_generator)

    items = []
    f = ensure_future(consume_async_generator(
        async_gen, lambda: False, items.append))

    # Run the event loop until all items are collected.
    get_event_loop().run_until_complete(f)
    assert items == [1, 10]

    # Check that `consume_async_generator` didn't fail.
    assert f.result() is None