aqua-playground/aqua/examples/closures.aqua

73 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-11-04 13:13:26 +03:00
module Closure declares *
import "@fluencelabs/aqua-lib/builtin.aqua"
2022-08-02 18:14:38 +03:00
export LocalSrv, closureIn, closureOut, closureBig, closureOut2, lng58Bug
2021-11-04 13:13:26 +03:00
service MyOp("op"):
identity(s: string) -> string
service LocalSrv("local_srv"):
inside: -> ()
func closureIn(peer1: string) -> string:
variable = "const"
co on peer1:
p1Id <- MyOp.identity("co on")
closure = (s: string) -> string:
if s == "in":
LocalSrv.inside()
p2Id <- MyOp.identity(s)
<- p2Id
p <- closure("in")
<- p
func closureOut(peer2: string) -> Info:
on peer2:
2022-03-10 15:23:05 +03:00
closure = (s: string) -> Info:
if s == "in":
LocalSrv.inside()
p2Id <- Peer.identify()
<- p2Id
p2Id <- closure("on")
2021-11-04 14:26:50 +03:00
<- p2Id
2022-03-14 12:14:06 +03:00
func closureOut2(peer2: string) -> Info:
closure = func (s: string) -> Info:
if s == "in":
LocalSrv.inside()
p2Id <- Peer.identify()
<- p2Id
on peer2:
p2Id <- closure("on")
<- p2Id
2022-03-10 15:23:05 +03:00
2021-11-04 14:26:50 +03:00
func closureBig(peer1: string, peer2: string) -> string, string:
variable = "const"
co on peer1:
p1Id <- MyOp.identity("co on")
2022-03-14 16:07:15 +03:00
closure = func (s: string) -> string:
2021-11-04 14:26:50 +03:00
p2Id: *string
if s == "in":
p2 <- MyOp.identity(s)
p2Id <<- p2
else:
p2Info <- Peer.identify()
p2Id <<- p2Info.external_addresses!0
<- p2Id!
p <- closure("in")
on peer2:
p2Id <- closure("on")
2022-08-02 18:14:38 +03:00
<- p, p2Id
func lng58Bug() -> string:
status: *string
waiting = ():
avava: *string
avava <<- "frerf"
status <<- "ok"
waiting()
<- status!