mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-12 17:55:33 +00:00
Add config to JS backend similar to it's TS counterpart (#196)
This commit is contained in:
parent
d24e77b5e3
commit
fbc34a793a
@ -43,12 +43,15 @@ case class JavaScriptFunc(func: FuncCallable) {
|
||||
val returnVal =
|
||||
func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise")
|
||||
|
||||
val configArgName ="config"
|
||||
|
||||
s"""
|
||||
|export async function ${func.funcName}(client${if (func.args.isEmpty) ""
|
||||
else ", "}${argsJavaScript}) {
|
||||
else ", "}${argsJavaScript}, $configArgName) {
|
||||
| let request;
|
||||
| $configArgName = $configArgName || {};
|
||||
| const promise = new Promise((resolve, reject) => {
|
||||
| request = new RequestFlowBuilder()
|
||||
| var r = new RequestFlowBuilder()
|
||||
| .disableInjections()
|
||||
| .withRawScript(
|
||||
| `
|
||||
@ -73,7 +76,10 @@ case class JavaScriptFunc(func: FuncCallable) {
|
||||
| .handleTimeout(() => {
|
||||
| reject('Request timed out for ${func.funcName}');
|
||||
| })
|
||||
| .build();
|
||||
| if(${configArgName}.ttl) {
|
||||
| r.withTTL(${configArgName}.ttl)
|
||||
| }
|
||||
| request = r.build();
|
||||
| });
|
||||
| await client.initiateFlow(request);
|
||||
| return ${returnVal};
|
||||
|
@ -66,9 +66,8 @@ case class TypeScriptFunc(func: FuncCallable) {
|
||||
else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> {
|
||||
| let request: RequestFlow;
|
||||
| const promise = new Promise<$retType>((resolve, reject) => {
|
||||
| request = new RequestFlowBuilder()
|
||||
| const r = new RequestFlowBuilder()
|
||||
| .disableInjections()
|
||||
| .withTTL($configArgName?.ttl || 5000)
|
||||
| .withRawScript(
|
||||
| `
|
||||
|${tsAir.show}
|
||||
@ -92,7 +91,10 @@ case class TypeScriptFunc(func: FuncCallable) {
|
||||
| .handleTimeout(() => {
|
||||
| reject('Request timed out for ${func.funcName}');
|
||||
| })
|
||||
| .build();
|
||||
| if(${configArgName}?.ttl) {
|
||||
| r.withTTL(${configArgName}.ttl)
|
||||
| }
|
||||
| request = r.build();
|
||||
| });
|
||||
| await $clientArgName.initiateFlow(request!);
|
||||
| return ${returnVal};
|
||||
|
Loading…
Reference in New Issue
Block a user