Skip to content

Commit

Permalink
docs(course): update example to match network type
Browse files Browse the repository at this point in the history
Thanks Daniel
  • Loading branch information
symbiont-stevan-andjelkovic committed Feb 3, 2022
1 parent 116ea80 commit 3fc2cea
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions doc/advanced-testing-mini-course/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@ eventLoop nw nodes = do
connectAllNodesToEachOther nw nodes
-- ^ Or do this as part of creating `Network`.
let env = nodes `zip` initialStates
go env
go env []
where
go env = do
(receiver, msg, time) <- select socks
(outgoing, env') <- step env receiver msg time
send nw outgoing
go env'
go env outgoing = do
(receiver, msg, time) <- select outgoing
(outgoing', env') <- step env receiver msg time
go env' outgoing'

fakeSend :: Heap -> Addr -> Msg -> (Heap, ())
fakeSend heap addr msg = do
t <- genArrivalTime
(enqueue (addr, msg, t) heap, ())

fakeRecv :: Heap -> (Heap, (Addr, Msg, Time))
fakeRecv = dequeue -- XXX: partial function

newFakeNetwork :: IO Network
newFakeNetwork = do
heap <- newIORef emptyHeap
let send = do
let select outgoing = do
h <- readIORef heap
let (h', ()) = fakeSend h
writeIORef heap h'
let h' = fakeSendAll h outgoing
(h'', incoming) = fakeRecv h'
writeIORef heap h''
return incoming
...
return Network {..}
```

0 comments on commit 3fc2cea

Please sign in to comment.