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.

Support direct .__await__

See original GitHub issue

Hey there, seems like a nice library. It’s just a small suggestion and opinion, but you can add __await__ for the queries, instead of kind of an annoying .run every time

class Q:
    async def _actual_call(self) -> T:
        # .... do_some_work .... '
        return 

    def __await__(self) -> Generator[None, None, T]:
        return self._actual_call().__await__()

q = Q()
await q

Suggestion related to picollo/query/base::Query

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dantownsendcommented, Nov 6, 2020

@sinisaos I’ll keep .run() as the default way of doing things in the docs. It makes it slightly more future proof, as run() can accept arguments - currently it’s just whether or not to run the query in a connection pool, which is mostly used for testing purposes, but there may be other arguments which need to be added in the future. The __await__ magic method can be there as a convenience, for people who prefer the more compact syntax. I won’t add the __call__ magic method for now - it’s just too weird.

0reactions
dantownsendcommented, Nov 8, 2020

@sinisaos Good suggestion - I’ll take a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

await - JavaScript - MDN Web Docs
The await operator is used to wait for a Promise and get its fulfillment value. It can only be used inside an async...
Read more >
Async/await - The Modern JavaScript Tutorial
The keyword await makes JavaScript wait until that promise settles and returns its result. Here's an example with a promise that resolves in...
Read more >
Javascript: async and await, a Complete Guide | by Harsh Patel
Start by declaring the function as async . This declaration allows await to be used from within. The asynchronous routine ( fetch in...
Read more >
Async Await performance - Direct method call vs Task wrapper ...
A small program that I have created to understand the working of Async Await and calling the async method in a for loop,...
Read more >
JavaScript async and await - in plain English, please
The await keyword is for making the JavaScript function execution wait until a promise is settled(either resolved or rejected) and value/error ...
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