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 =
|
val returnVal =
|
||||||
func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise")
|
func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise")
|
||||||
|
|
||||||
|
val configArgName ="config"
|
||||||
|
|
||||||
s"""
|
s"""
|
||||||
|export async function ${func.funcName}(client${if (func.args.isEmpty) ""
|
|export async function ${func.funcName}(client${if (func.args.isEmpty) ""
|
||||||
else ", "}${argsJavaScript}) {
|
else ", "}${argsJavaScript}, $configArgName) {
|
||||||
| let request;
|
| let request;
|
||||||
|
| $configArgName = $configArgName || {};
|
||||||
| const promise = new Promise((resolve, reject) => {
|
| const promise = new Promise((resolve, reject) => {
|
||||||
| request = new RequestFlowBuilder()
|
| var r = new RequestFlowBuilder()
|
||||||
| .disableInjections()
|
| .disableInjections()
|
||||||
| .withRawScript(
|
| .withRawScript(
|
||||||
| `
|
| `
|
||||||
@ -73,7 +76,10 @@ case class JavaScriptFunc(func: FuncCallable) {
|
|||||||
| .handleTimeout(() => {
|
| .handleTimeout(() => {
|
||||||
| reject('Request timed out for ${func.funcName}');
|
| reject('Request timed out for ${func.funcName}');
|
||||||
| })
|
| })
|
||||||
| .build();
|
| if(${configArgName}.ttl) {
|
||||||
|
| r.withTTL(${configArgName}.ttl)
|
||||||
|
| }
|
||||||
|
| request = r.build();
|
||||||
| });
|
| });
|
||||||
| await client.initiateFlow(request);
|
| await client.initiateFlow(request);
|
||||||
| return ${returnVal};
|
| return ${returnVal};
|
||||||
|
@ -66,9 +66,8 @@ case class TypeScriptFunc(func: FuncCallable) {
|
|||||||
else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> {
|
else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> {
|
||||||
| let request: RequestFlow;
|
| let request: RequestFlow;
|
||||||
| const promise = new Promise<$retType>((resolve, reject) => {
|
| const promise = new Promise<$retType>((resolve, reject) => {
|
||||||
| request = new RequestFlowBuilder()
|
| const r = new RequestFlowBuilder()
|
||||||
| .disableInjections()
|
| .disableInjections()
|
||||||
| .withTTL($configArgName?.ttl || 5000)
|
|
||||||
| .withRawScript(
|
| .withRawScript(
|
||||||
| `
|
| `
|
||||||
|${tsAir.show}
|
|${tsAir.show}
|
||||||
@ -92,7 +91,10 @@ case class TypeScriptFunc(func: FuncCallable) {
|
|||||||
| .handleTimeout(() => {
|
| .handleTimeout(() => {
|
||||||
| reject('Request timed out for ${func.funcName}');
|
| reject('Request timed out for ${func.funcName}');
|
||||||
| })
|
| })
|
||||||
| .build();
|
| if(${configArgName}?.ttl) {
|
||||||
|
| r.withTTL(${configArgName}.ttl)
|
||||||
|
| }
|
||||||
|
| request = r.build();
|
||||||
| });
|
| });
|
||||||
| await $clientArgName.initiateFlow(request!);
|
| await $clientArgName.initiateFlow(request!);
|
||||||
| return ${returnVal};
|
| return ${returnVal};
|
||||||
|
Loading…
Reference in New Issue
Block a user