https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Paul N

06/12/2019, 7:15 PM
An architectural question: I have a REST function that fires off a call to Azure to create a VM. The VM creation can take 15 minutes or so, so my REST function returns straight away. What I want to do is when I kick off the call to create the VM, I then want to kick off a long running, asynchronous process that polls Azure every now and then to see if the VM has been created. Once it has been created, it then calls another Azure REST service. So I assume I can do this via coroutines. Can I fire off a coroutine from my initial REST function, and have it running in the background even after the REST call has returned to the client ? So in effect, can I fire off a long running, fire and forget, async task from a simple REST endpoint that returns straight away ? Is this done just by using launch ?
d

Dico

06/12/2019, 7:41 PM
Fire and forget = GlobalScope.launch
p

Paul N

06/12/2019, 8:28 PM
Great - thanks !
13 Views