Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ refactor ] dont automatically start a fiber with uvForever #18

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/src/Docs/UV/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ parameters {auto l : UVLoop}
putStrLn "Hello World"
ref <- newIORef 0
putStrLn "Starting the counter"
counter <- onIdle (checkCounter ref)
counter <- start $ onIdle (checkCounter ref)

res <- raceAny [onSignal SIGINT, once 5000]

Expand Down Expand Up @@ -129,8 +129,8 @@ parameters {auto l : UVLoop}
There (Here _) => putOutLn "Stream interrupted by timeout"
_ => putOutLn "Stream exhausted."

main : IO ()
main = runDoc fileStreamExample
-- main : IO ()
-- main = runDoc fileStreamExample
```

## An echo Server
Expand All @@ -146,7 +146,7 @@ parameters {auto l : UVLoop}
onConnection ac server = do
putOutLn "Got a connection"
client <- acceptTcp server
_ <- streamReadWrite ac client $ \case
_ <- start $ streamReadWrite ac client $ \case
Done => pure (Just ())
Data val => write client val $> Nothing
Err x => throw x
Expand All @@ -155,16 +155,16 @@ parameters {auto l : UVLoop}
echo : DocIO ()
echo = do
ac <- sizedAlloc 0xffff
server <- listenTcp "0.0.0.0" 7000 $ \case
server <- start $ listenTcp "0.0.0.0" 7000 $ \case
Left err => putErrLn "Error when receiving request: \{err}" $> Nothing
Right srv => onConnection ac srv

ignore $ onSignal SIGINT
putOutLn "Shutting down server..."
cancel

-- main : IO ()
-- main = runDoc echo
main : IO ()
main = runDoc echo
```

<!-- vi: filetype=idris2:syntax=markdown
Expand Down
24 changes: 12 additions & 12 deletions pack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ ipkg = "test.ipkg"
type = "local"
path = "docs"
ipkg = "uv-docs.ipkg"

[custom.all.array]
type = "git"
url = "https://github.com/stefan-hoeck/idris2-array"
commit = "latest:main"
ipkg = "array.ipkg"

[custom.all.bytestring]
type = "git"
url = "https://github.com/stefan-hoeck/idris2-bytestring"
commit = "latest:main"
ipkg = "bytestring.ipkg"
#
# [custom.all.array]
# type = "git"
# url = "https://github.com/stefan-hoeck/idris2-array"
# commit = "latest:main"
# ipkg = "array.ipkg"
#
# [custom.all.bytestring]
# type = "git"
# url = "https://github.com/stefan-hoeck/idris2-bytestring"
# commit = "latest:main"
# ipkg = "bytestring.ipkg"
6 changes: 3 additions & 3 deletions src/System/UV/Idle.idr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parameters {auto l : UVLoop}

||| Runs the given `IO` action during the "idle" phase of the event loop.
export
onIdle : Async es (Maybe a) -> Async es (Fiber es a)
onIdle : Async es (Maybe a) -> Async es a
onIdle as = do
pi <- mkIdle
uvForever' as pi idle_stop (uv_idle_start pi . const)
Expand All @@ -50,7 +50,7 @@ parameters {auto l : UVLoop}

||| Runs the given `IO` action during the "check" phase of the event loop.
export
onCheck : Async es (Maybe a) -> Async es (Fiber es a)
onCheck : Async es (Maybe a) -> Async es a
onCheck as = do
pi <- mkCheck
uvForever' as pi check_stop (uv_check_start pi . const)
Expand All @@ -61,7 +61,7 @@ parameters {auto l : UVLoop}

||| Runs the given `IO` action during the "prepare" phase of the event loop.
export
onPrepare : Async es (Maybe a) -> Async es (Fiber es a)
onPrepare : Async es (Maybe a) -> Async es a
onPrepare as = do
pi <- mkPrepare
uvForever' as pi prepare_stop (uv_prepare_start pi . const)
6 changes: 3 additions & 3 deletions src/System/UV/Loop.idr
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ parameters {auto has : Has UVError es}
-> (ptr : r)
-> (close : r -> Async [] ())
-> ((a -> IO ()) -> IO Int32)
-> Async es (Fiber es b)
-> Async es b
uvForever to p close reg =
start $ finally
finally
(do
cc <- self
forever $ \cb => do
Expand All @@ -129,7 +129,7 @@ parameters {auto has : Has UVError es}
-> (ptr : r)
-> (close : r -> Async [] ())
-> (IO () -> IO Int32)
-> Async es (Fiber es b)
-> Async es b
uvForever' as p close reg = uvForever (const as) p close (\f => reg (f ()))

export
Expand Down
2 changes: 1 addition & 1 deletion src/System/UV/Pipe.idr
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ parameters {auto l : UVLoop}
streamStdin :
AllocCB
-> (ReadRes ByteString -> Async es (Maybe a))
-> Async es (Fiber es a)
-> Async es a
streamStdin ac run = use1 stdinOpen $ \h => streamRead ac h run
6 changes: 3 additions & 3 deletions src/System/UV/Stream.idr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ parameters {auto l : UVLoop}
-> Ptr t
-> {auto 0 cstt : PCast t Stream}
-> (ReadRes ByteString -> Async es (Maybe a))
-> Async es (Fiber es a)
-> Async es a
streamRead ac h run = do
uvForever run h (\x => uv_read_stop x) $ \cb =>
uv_read_start h ac (\_,n,buf => toMsg n buf >>= cb)
Expand All @@ -56,7 +56,7 @@ parameters {auto l : UVLoop}
-> Ptr t
-> {auto 0 cstt : PCast t Stream}
-> (ReadRes ByteString -> Async es (Maybe a))
-> Async es (Fiber es a)
-> Async es a
streamReadWrite ac h run = do
uvForever run h (close_stream . castPtr) $ \cb =>
uv_read_start h ac (\_,n,buf => toMsg n buf >>= cb)
Expand All @@ -76,7 +76,7 @@ parameters {auto l : UVLoop}
Ptr t
-> {auto 0 cst : PCast t Stream}
-> (Either UVError (Ptr Stream) -> Async es (Maybe a))
-> Async es (Fiber es a)
-> Async es a
listen {cst} server run =
uvForever run server (release . castPtr @{cst}) $ \cb =>
uv_listen server 128 $ \p,res =>
Expand Down
2 changes: 1 addition & 1 deletion src/System/UV/TCP.idr
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ parameters {auto l : UVLoop}
(addresss : String)
-> (port : Bits16)
-> (run : Either UVError (Ptr Stream) -> Async es (Maybe a))
-> Async es (Fiber es a)
-> Async es a
listenTcp address port run =
use1 (mallocPtr SockAddrIn) $ \addr => do
uv (uv_ip4_addr address port addr)
Expand Down
2 changes: 1 addition & 1 deletion src/System/UV/Timer.idr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parameters {auto l : UVLoop}
repeatedly :
(timeout,repeat : Bits64)
-> Async es (Maybe a)
-> Async es (Fiber es a)
-> Async es a
repeatedly t r run = do
pt <- mkTimer
uvForever' run pt timer_stop $ \cb => uv_timer_start pt (\_ => cb) t r
Expand Down
Loading