-
Notifications
You must be signed in to change notification settings - Fork 33
Feature/async incremental #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| module Main where | ||
|
|
||
| import Prelude | ||
| import Data.Either | ||
| import Data.Maybe | ||
| import Control.Monad.Eff | ||
| import Control.Monad.Eff.Console(log,CONSOLE()) | ||
| import Control.Monad.Eff.Exception | ||
|
|
||
| import Node.FS | ||
| import qualified Node.FS.Async as A | ||
| import qualified Node.Path as FP | ||
| import qualified Node.Buffer as B | ||
|
|
||
| -- exercise the file descriptor based async IO functions | ||
|
|
||
| main :: forall eff . Eff (fs::FS,err::EXCEPTION,console::CONSOLE|eff) Unit | ||
| main = do | ||
| let path1 = FP.concat( ["examples", "TestAsync.purs"] ) | ||
| path2 = FP.concat( ["examples", "TestAsync.purs.partial"] ) | ||
| buf = B.create 1000 | ||
| A.fdOpen path1 R Nothing $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern of matching on the let takeRight = either (\err -> log (...))
A.fdOpen path1 R Nothing $ takeRight $ \fd -> do
log ("opened " ++ path1)
A.fdNext fd buf $ takeRight $ \nbytes -> do
...Also maybe throw an exception rather than just logging that an error happened? Then we could put this file into
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just meant to be a trivial demo to meet your request "Nothing fancy - I'm just thinking something like calling them once and checking nothing obviously wrong happens". Are there plans to build a test suite for this library? The existing example file doesn't typecheck with the current compiler/libraries.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah yes of course, sorry, disregard that then. In that case let's leave this as-is for now. I certainly agree with you that a test suite would be nice. The only reason we don't, as far as I'm aware, is that nobody has gotten around to it yet. I might have a go soon. |
||
| (Right fd) -> do | ||
| log ("opened " ++ path1) | ||
| A.fdNext fd buf $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right nbytes) -> do | ||
| log ("read " ++ show nbytes) | ||
| A.fdOpen path2 W Nothing $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right fd2) -> do | ||
| log ("opened " ++ path2) | ||
| A.fdAppend fd2 buf $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right nbytes) -> do | ||
| log ("wrote " ++ show nbytes) | ||
| A.fdClose fd2 $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right _) -> do | ||
| log ("closed " ++ path2) | ||
| A.fdClose fd $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right _) -> do | ||
| log ("closed " ++ path1) | ||
| A.unlink path2 $ \v -> case v of | ||
| (Left err) -> log ("err:" ++ show err) | ||
| (Right _) -> log ("unlinked " ++ path2) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that reminds me, we should be using
^0.2.0ofnode-buffer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually don't worry about this, I'll take care of it later.