How do i create a class implementing a suspend blo...
# coroutines
s
How do i create a class implementing a suspend block?
Copy code
class LambdaClass : suspend () -> Unit {

    override fun invoke() {
        // do something
    }

}
z
I don't think you can make a suspending function a supertype at the moment
s
yeah looks like it
z
...would be handy
g
What is your use case? You cannot have suspend constructor.
Just use builder suspend function instead
s
Its not about suspend constructor, just a class to represent a suspend lambda block
with a regular lambda block, i can keep all logic including helper methods within the class and just create an instance of it at use site
I was wondering if that was possible with a suspend lambda
g
Yeah, I see what you mean
b
do you want something like
class MyLambda() { suspend operator fun invoke() {} }
?
g
This is not direct relplacement, you cannot use such class as lambda
s
yeah, that doesn't do it