question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question regarding awaitables

See original GitHub issue

Hi @maxfischer2781 , First of all, thanks for developing asyncstdlib!

I am writing icontract, a library for design-by-contract in Python. As Python 3 lacks the support for async lambdas (see the Python issue 33447) I am searching for a workaround so that contracts can still be defined as lambda functions. Instead of a concrete (realized) value, the lambda returns a coroutine. I am wondering whether asyncstdlib can fit the bill?

I played with it in the console, but couldn’t really figure out how to achieve what I need. Here is a short code snippet defining functions that I’d need:

T = TypeVar('T')

async def awaited_all(aws: Iterable[Awaitable[T]]) -> bool:
    """Await each item in ``aws`` and then check that ``all`` holds."""
    for awaitable in aws:
        if not await awaitable:
            return False

    return True

U = TypeVar('U')
V = TypeVar('V')

async def awaited_to(func: Callable[[U], V], awaitable: Awaitable[U]) -> V:
    """Await the ``awaitable`` and then apply ``func`` on it."""
    return func(await awaitable)

As you see, the implementation is quite simple. As far as I understood, the focus of asyncstdlib is on async iterators instead of sync iterators over awaitables, is that correct?

If asyncstdlib can not be used, are you maybe aware of a library that implements the functions that I need?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
mristincommented, Feb 22, 2021

No worries – brain storming is important 😃.

I would argue against complex implementations. First, because the library like this needs a high level of reliability (simple = “obviously no bugs, rather than no obvious bugs”). Second, this lib aims to be heavily used in many places throughout the system, so a small overhead accumulates and can cause a significant slow down.

0reactions
mristincommented, Feb 23, 2021

Closing since this issue was forked into issues #28 and #33.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vb.net - Await iterating a datatable with awaitable methods
Await iterating a datatable with awaitable methods · Ask Question ... I have the following Async Method, that awaits separate methods on a...
Read more >
Python Asyncio Part 2 – Awaitables, Tasks, and Futures
So the question of how to create a task seems like an important one. Creating a task is a simple matter, and can...
Read more >
Async IO in Python: A Complete Walkthrough
This tutorial is built to help you answer that question, giving you a ... The result of calling a coroutine on its own...
Read more >
Waiting in asyncio
It's up to you to await and dispatch. Will wrap in tasks, but will warn about it because that means you get a...
Read more >
Interview question "When we use async/await, how does ...
I have this question on a list to prepare for and I can't think of an answer ... how does the main thread...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found