resolve promise instantly if a function returns nothing (#60)

* resolve promise instantly if a function returns nothing

* set return value by func.ret

Co-authored-by: Dmitry Kurinskiy <dmitry@fluence.one>
This commit is contained in:
Dima 2021-04-15 09:54:03 +03:00 committed by GitHub
parent 28830feafd
commit c0cdb07bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,9 @@ case class TypescriptFunc(func: FuncResolved) {
.map(_._2)
.fold("void")(typeToTs)
val returnVal =
func.func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise")
s"""
|export async function ${func.name}(client: FluenceClient${if (func.func.args.isEmpty) ""
else ", "}${argsTypescript}): Promise<$retType> {
@ -75,7 +78,7 @@ case class TypescriptFunc(func: FuncResolved) {
| .build();
| });
| await client.initiateFlow(request);
| return promise;
| return ${returnVal};
|}
""".stripMargin
}