Can we use launch like this in Spring Webflux Cont...
# spring
n
Can we use launch like this in Spring Webflux Controller
Copy code
suspend fun test() : Response = coroutineScope {
    launch {
        doSomething()
    }

    Response(“pass”)
}
Will doSomething will keep on running in background once Response is returned. I have used async but not launch
d
Your test method wont return response until launch completes
n
Hmm I thought launch would be just fire and forget.
Looks like I can do this to achieve what I want
Copy code
CoroutineScope(Dispatchers.Default).launch {
    doSomething()
}
Are there any problem with this approach.
d
You would be breaking structured concureency - ie yout launch coroutine would no longer be a child of scope from test function
n
Yeah but here since this launch happens at last I think it will be fine I just don’t want to wait launch to complete and return Result I want to return Result immediately and keep launch doing it’s work in background. Are there other ways to achieve this.
d
If you dont care about that scope you could just use GlobalScope, if you do care about it and need to track it - I'd store it in a class field so you could always cancel children if needed