Has anyone managed to get async calls working insi...
# python
Has anyone managed to get async calls working inside a dynamic resource provider? I need to make a few HTTP calls, but can't quite sort out the magic to get Pulumi to work with them.
Can you say more about what isn’t working as you expect? Perhaps with code samples?
I may be doing something wrong, as I've not had occasion to do async Python before, but it seems like I'd need something like this:
Copy code
async def create(self, inputs):
    let x = await make_an_http_request(...)
    # do stuff with x
    return CreateResult(...)
but I get
RuntimeWarning: coroutine 'create' was never awaited
You can make API calls in python without using async/await. Generally async/await is not used unless you are specifically using a library that uses asyncio.
You probably want to use something like requests which doesn’t use asyncio and just immediately awaits the output of the api call.
That being said if you do need to use an asyncio library, you’ll need to make sure that all asynchronous tasks are resolved within the
function, because that function itself cannot be
. So you’ll probably need to do something like:
Copy code
def create(self, inputs):
    x = asyncio.run(make_an_http_request(...))
    return CreateResult(...)
returns an Awaitable
Ah, I see; thanks!