, .
, , , .eof
. , , .get
, Nil
. , Got line
.
.lines
for $*IN.lines { put "Got line $_" }
.get
, , .
loop {
with $*IN.get {
put "Got line $_"
} else {
last
}
}
:
$*IN.lines.Supply
react {
start whenever $*IN.lines.Supply {
put "Got line $_";
LAST done; # finish the outer 「react」 block when this closes
}
whenever Supply.interval(1) {
put DateTime.now.hh-mm-ss
}
}
22:46:33
22:46:34
a
Got line a
22:46:35
22:46:36
b
Got line b
22:46:37
22:46:38
c
Got line c
22:46:39
22:46:40
d
Got line d
22:46:41
22:46:42
^D # represents Ctrl+D
start
, Supply.interval(1)
.
- , :
my \in-supply = supply {
# 「await start」 needed so this won't block other things on this thread.
await start loop {
with $*IN.get { # defined (so still open)
emit $_
} else { # not defined (closed)
done; # stop the Supply
# last # stop this loop (never reached)
}
}
}
react {
whenever in-supply {
put "Got line $_";
LAST done # finish the outer 「react」 block when this closes
}
whenever Supply.interval(1) {
put DateTime.now.hh-mm-ss
}
}