Hi, is there a way to write anonymous suspend func...
# announcements
a
Hi, is there a way to write anonymous suspend function? ``` val func = { // <- here I cannot call suspend functions } ``
t
There's a special syntax to define a
suspend
lambda :
Copy code
val func = suspend {
    delay(100)
}
s
Its actually just a normal inline function
a
it will work with no argument
but actually I need an anonymous functions with parameters
Copy code
val func = suspend { from: Int ->

            }
don't work
s
Then put the proper type on the func:
val func : suspend (Int) -> Unit = {}
a
so actually to write anonymous suspend function I need to assign it to some variable with explicitly defined type?
s
Pretty sure suspend has to be inferred for lambdas
d
Yeah sadly this is not yet supported.
You can declare the type of the variable explicitly as a workaround
a
ok, thanks
s
If you want then you can still make your own
suspend
function like the stdlib one that takes one, two, three args or whatever you need
d
But you would need to name it differently