Compare commits
2 Commits
7c72ea5732
...
5f45f76452
Author | SHA1 | Date |
---|---|---|
|
5f45f76452 | |
|
403e54878c |
|
@ -127,10 +127,10 @@
|
||||||
"taps"
|
"taps"
|
||||||
],
|
],
|
||||||
"path": "/nix/store/n86g5fw60z1k53bn35zvrwlwmyk3ixdn-source",
|
"path": "/nix/store/n86g5fw60z1k53bn35zvrwlwmyk3ixdn-source",
|
||||||
"rev": "756cb07b4f874181ad34c370cad6082ee65f646d",
|
"rev": "6ec1491c178bd37491ca55c012675bd525391e29",
|
||||||
"sha256": "0dp7ml3kj2fi6isvjkkxf02hwj0gshx6qra0ghnk2cbfykbcgfp8",
|
"sha256": "0dp7ml3kj2fi6isvjkkxf02hwj0gshx6qra0ghnk2cbfykbcgfp8",
|
||||||
"srcDir": "src",
|
"srcDir": "src",
|
||||||
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/756cb07b4f874181ad34c370cad6082ee65f646d.tar.gz"
|
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/6ec1491c178bd37491ca55c012675bd525391e29.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"date": "2024-04-02T15:38:57+01:00",
|
"date": "2024-04-02T15:38:57+01:00",
|
||||||
|
|
|
@ -127,7 +127,7 @@ else:
|
||||||
discard close(fd)
|
discard close(fd)
|
||||||
driver.timers.excl(fd)
|
driver.timers.excl(fd)
|
||||||
|
|
||||||
proc spawnTimerActor*(turn: var Turn; ds: Cap): Actor {.discardable.} =
|
proc spawnTimerDriver*(turn: var Turn; ds: Cap): Actor {.discardable.} =
|
||||||
## Spawn a timer actor that responds to
|
## Spawn a timer actor that responds to
|
||||||
## dataspace observations of timeouts on `ds`.
|
## dataspace observations of timeouts on `ds`.
|
||||||
linkActor(turn, "timers") do (turn: var Turn):
|
linkActor(turn, "timers") do (turn: var Turn):
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20240402"
|
version = "20240403"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Syndicated actors for conversational concurrency"
|
description = "Syndicated actors for conversational concurrency"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import taps
|
||||||
|
import solo5
|
||||||
|
import syndicate, syndicate/relays
|
||||||
|
import preserves
|
||||||
|
|
||||||
|
acquireDevices([("relay", netBasic)], netAcquireHook)
|
||||||
|
|
||||||
|
type Netif {.preservesRecord: "netif"} = object
|
||||||
|
device, ipAddr: string
|
||||||
|
|
||||||
|
proc spawnNetifActor(turn: var Turn; ds: Cap) =
|
||||||
|
spawnActor(turn, "netif") do (turn: var Turn):
|
||||||
|
let facet = turn.facet
|
||||||
|
onInterfaceUp do (device: string; ip: IpAddress):
|
||||||
|
run(facet) do (turn: var Turn):
|
||||||
|
if not ip.isLinkLocal:
|
||||||
|
discard publish(turn, ds, Netif(device: device, ipAddr: $ip))
|
||||||
|
|
||||||
|
runActor("relay-test") do (turn: var Turn):
|
||||||
|
let root = turn.facet
|
||||||
|
onStop(turn) do (turn: var Turn):
|
||||||
|
quit()
|
||||||
|
let ds = newDataspace(turn)
|
||||||
|
spawnNetifActor(turn, ds)
|
||||||
|
spawnRelays(turn, ds)
|
||||||
|
var
|
||||||
|
route: Route
|
||||||
|
pr = parsePreserves $solo5_start_info.cmdline
|
||||||
|
if route.fromPreserves pr:
|
||||||
|
echo "parsed route ", route.toPreserves
|
||||||
|
during(turn, ds, Netif?:{1: grab()}) do (ip: string):
|
||||||
|
echo "Acquired address ", ip
|
||||||
|
resolve(turn, ds, route) do (turn: var Turn; ds: Cap):
|
||||||
|
echo "route resolved!"
|
||||||
|
echo "stopping root facet"
|
||||||
|
stop(turn, root)
|
|
@ -0,0 +1,3 @@
|
||||||
|
define:ipv6Enabled
|
||||||
|
define:traceSyndicate
|
||||||
|
import:"std/assertions"
|
|
@ -0,0 +1,25 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import std/times
|
||||||
|
import solo5
|
||||||
|
import syndicate, syndicate/drivers/timers
|
||||||
|
|
||||||
|
acquireDevices()
|
||||||
|
|
||||||
|
runActor("timer-test") do (turn: var Turn):
|
||||||
|
let timers = newDataspace(turn)
|
||||||
|
spawnTimerDriver(turn, timers)
|
||||||
|
|
||||||
|
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
|
||||||
|
echo "now in 13th bʼakʼtun"
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 3)) do (turn: var Turn):
|
||||||
|
echo "third timer expired"
|
||||||
|
stopActor(turn)
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 1)) do (turn: var Turn):
|
||||||
|
echo "first timer expired"
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 2)) do (turn: var Turn):
|
||||||
|
echo "second timer expired"
|
|
@ -0,0 +1,2 @@
|
||||||
|
define:ipv6Enabled
|
||||||
|
import:"std/assertions"
|
|
@ -2,11 +2,11 @@
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/times
|
import std/times
|
||||||
import syndicate, syndicate/actors/timers
|
import syndicate, syndicate/drivers/timers
|
||||||
|
|
||||||
runActor("timer-test") do (turn: var Turn):
|
runActor("timer-test") do (turn: var Turn):
|
||||||
let timers = newDataspace(turn)
|
let timers = newDataspace(turn)
|
||||||
spawnTimerActor(turn, timers)
|
spawnTimerDriver(turn, timers)
|
||||||
|
|
||||||
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
|
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
|
||||||
echo "now in 13th bʼakʼtun"
|
echo "now in 13th bʼakʼtun"
|
||||||
|
|
Loading…
Reference in New Issue