File tree Expand file tree Collapse file tree 1 file changed +0
-5
lines changed
Expand file tree Collapse file tree 1 file changed +0
-5
lines changed Original file line number Diff line number Diff line change @@ -7,19 +7,16 @@ open Std.Net
77
88open Std.Net
99
10- -- Using this function to create IO Error. For some reason the assert! is not pausing the execution.
1110def assertBEq [BEq α] [ToString α] (actual expected : α) : IO Unit := do
1211 unless actual == expected do
1312 throw <| IO.userError <|
1413 s! "expected '{ expected} ', got '{ actual} '"
1514
16- -- Define the Async monad
1715structure Async (α : Type ) where
1816 run : IO (AsyncTask α)
1917
2018namespace Async
2119
22- -- Monad instance for Async
2320instance : Monad Async where
2421 pure x := Async.mk (pure (AsyncTask.pure x))
2522 bind ma f := Async.mk do
@@ -53,14 +50,12 @@ def timeout (a : AsyncTask α) (time : Std.Time.Millisecond.Offset) : IO (AsyncT
5350 | .ok res => Task.pure (.ok res)
5451 | .error _ => Task.pure (.error (IO.userError "Timeout." ))
5552
56- -- Await function to simplify AsyncTask handling
5753def await (task : IO (AsyncTask α)) : Async α :=
5854 Async.mk task
5955
6056instance : MonadLift IO Async where
6157 monadLift io := Async.mk (io >>= (pure ∘ AsyncTask.pure))
6258
63- /-- Joe is another client. -/
6459def runDNS : Async Unit := do
6560 let infos ← await <| (timeout (← DNS.getAddrInfo "google.com" "http" ) 10000 )
6661
You can’t perform that action at this time.
0 commit comments