mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-04-25 18:52:21 +00:00
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
/**
|
|
*
|
|
* This file is auto-generated. Do not edit manually: changes may be erased.
|
|
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
|
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
|
* Aqua version: 0.1.9-SNAPSHOT
|
|
*
|
|
*/
|
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
|
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
|
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
|
|
|
|
|
|
|
|
export async function checkStreams(client: FluenceClient, ch: string[], config?: {ttl?: number}): Promise<string[]> {
|
|
let request: RequestFlow;
|
|
const promise = new Promise<string[]>((resolve, reject) => {
|
|
const r = new RequestFlowBuilder()
|
|
.disableInjections()
|
|
.withRawScript(
|
|
`
|
|
(xor
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
|
(call %init_peer_id% ("getDataSrv" "ch") [] ch)
|
|
)
|
|
(call %init_peer_id% ("stringer-id" "returnString") ["first"] $stream)
|
|
)
|
|
(call %init_peer_id% ("stringer-id" "returnString") ["second"] $stream)
|
|
)
|
|
(fold ch b
|
|
(seq
|
|
(call %init_peer_id% ("stringer-id" "returnString") [b] $stream)
|
|
(next b)
|
|
)
|
|
)
|
|
)
|
|
(xor
|
|
(call %init_peer_id% ("callbackSrv" "response") [$stream])
|
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
|
)
|
|
)
|
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
|
)
|
|
|
|
`,
|
|
)
|
|
.configHandler((h) => {
|
|
h.on('getDataSrv', '-relay-', () => {
|
|
return client.relayPeerId!;
|
|
});
|
|
h.on('getDataSrv', 'ch', () => {return ch;});
|
|
h.onEvent('callbackSrv', 'response', (args) => {
|
|
const [res] = args;
|
|
resolve(res);
|
|
});
|
|
|
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
|
// assuming error is the single argument
|
|
const [err] = args;
|
|
reject(err);
|
|
});
|
|
})
|
|
.handleScriptError(reject)
|
|
.handleTimeout(() => {
|
|
reject('Request timed out for checkStreams');
|
|
})
|
|
if(config && config.ttl) {
|
|
r.withTTL(config.ttl)
|
|
}
|
|
request = r.build();
|
|
});
|
|
await client.initiateFlow(request!);
|
|
return promise;
|
|
}
|
|
|