diff --git a/aqua/examples/par.aqua b/aqua/examples/par.aqua index d82712c..dc19a4b 100644 --- a/aqua/examples/par.aqua +++ b/aqua/examples/par.aqua @@ -11,3 +11,24 @@ func parFunc( node: string, c: Info -> () ): t <- Peer.identify() c(t) par x <- ParService.call() + +func testTimeout(nodes: []string) -> string: + on HOST_PEER_ID: + + results: *Info + + for node <- nodes par: + on node: + results <- Peer.identify() + + timeout: *string + join results[999] + par timeout <- Peer.timeout(400, "timeout") + + status: *string + if timeout == nil: + status <<- "ok" + else: + status <<- timeout! + + <- status! diff --git a/src/__test__/examples.spec.ts b/src/__test__/examples.spec.ts index e81f51c..1396b33 100644 --- a/src/__test__/examples.spec.ts +++ b/src/__test__/examples.spec.ts @@ -7,7 +7,7 @@ import { funcCall } from '../examples/funcCall'; import { helloWorldCall } from '../examples/helloWorldCall'; import { foldCall } from '../examples/foldCall'; import {ifCall, ifWrapCall} from '../examples/if'; -import { parCall } from '../examples/parCall'; +import {parCall, testTimeoutCall} from '../examples/parCall'; import { complexCall } from '../examples/complex'; import { constantsCall } from '../examples/constantsCall'; import { returnNilCall, returnNoneCall, streamCall } from '../examples/streamCall'; @@ -109,6 +109,11 @@ describe('Testing examples', () => { expect(parCallResult).toBe('hello'); }); + it(' par.aqua testTimeout', async () => { + let testTimeoutResult = await testTimeoutCall(); + expect(testTimeoutResult).toBe('timeout'); + }); + it('helloWorld.aqua', async () => { let helloWorldResult = await helloWorldCall(); expect(helloWorldResult).toBe('Hello, NAME!'); diff --git a/src/examples/parCall.ts b/src/examples/parCall.ts index f58f4c8..9c43579 100644 --- a/src/examples/parCall.ts +++ b/src/examples/parCall.ts @@ -1,5 +1,6 @@ import { Fluence } from '@fluencelabs/fluence'; -import { parFunc, registerParService } from '../compiled/examples/par'; +import {parFunc, registerParService, testTimeout} from '../compiled/examples/par'; +import {config} from "../config"; export async function parCall() { const relayPeerId = Fluence.getPeer().getStatus().relayPeerId; @@ -21,3 +22,9 @@ export async function parCall() { return promise; } + +const relays = config.relays + +export async function testTimeoutCall() { + return testTimeout([relays[3].peerId, relays[4].peerId]) +}