On Tue, Jul 11, 2017 at 3:26 PM, Laurent Mazuel via Async-sig
<async-sig@python.org> wrote:
> But I got a warning if I decide to do not use this poller, RuntimeWarning: 
> coroutine 'foo' was never awaited
> ...
> I found 2 solutions to avoid the warning, and I currently prefer solution 2:
> 1- Return a function to call, and not a coroutine. The "await" statement 
> becomes:
>
>    obj = await optional_poller()
>
> 2- Return my initial object with an async method. This allows me to write 
> (something finally close to the current code):
>
>     async_poller = client.create(**parameters)
>     obj = async_poller.resource() # Get the initial resource information, but 
> the object is not actually created yet.
>     obj = await async_poller.result() # OPTIONAL

Either of those options sounds fine to me. Instead of creating your
coroutine object at the very beginning, create your coroutine
*function*. Wait until you know you're going to do your second
operation, and create your coroutine object then!

--Chris


>
> My async_poller object being something like:
>
>     class PollerOperation:
>          async def result(self):
>               ...async version of previous sync result()...
>
> So the questions are:
> - Does this seem a correct pattern?
> - Is there a simple way to achieve something like this:
>
>     obj = await async_poller
>
> meaning, I can win the "result()" syntax and directly "await" on the object 
> and get the result from magic function. I tried by subclassing some ABC 
> coroutine/awaitable, but wasn't able to find a correct syntax. I'm not even 
> sure this makes sense and respects the zen of Python 😊
>
> If it helps, I'm willing to use 3.5 as minimal requirement to get async 
> behavior.
>
> Thank you!!
>
> Laurent
> _______________________________________________
> Async-sig mailing list
> Async-sig@python.org
> https://mail.python.org/mailman/listinfo/async-sig
> Code of Conduct: https://www.python.org/psf/codeofconduct/
_______________________________________________
Async-sig mailing list
Async-sig@python.org
https://mail.python.org/mailman/listinfo/async-sig
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to