Closed RealyUniqueName closed 5 years ago
The same problem with the return type:
suspend function loadJson(url:String):MyData {
var json = await(load(url));
return Json.parse(json);
}
//outside of a coroutine
var data:MyData = loadJson(url); //Error: `loadJson()` does not return `MyData`, but something like `Promise<MyData>`
It would be better to specify the exact coroutine implementation as a return type:
suspend function loadJson(url:String):Promise<MyData> {
var json = await(load(url));
return Json.parse(json);
}
My idea was to use a @:coreType
abstract for the suspend functions, like Suspend<Void->Void>
which is incompatible with normal Void->Void
, and then this type would have a magic start
method or something from calling outside of coroutines. I thought I documented that, but I guess I only played with it in a toy implementation.
Yes, that's documented. I missed it. But what about reflection?
But what about reflection?
Honestly, I would leave the reflection questions to those who want to use reflection :) Let's implement it for the typed code and then see how reflection-friendly it can be.
Automatically adding a continuation argument to the user's code may lead to unexpected surprises.