-
Notifications
You must be signed in to change notification settings - Fork 177
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
"Lwt_unix.files_of_directory dir" fails if "dir" can't be read #265
Comments
I also tried: Lwt_unix.files_of_directory "/doesnotexist"
|> Lwt_stream.map_exn
|> Lwt_stream.filter_map (function Lwt_stream.Value v -> Some v | Lwt_stream.Error _ -> None)
|> Lwt_stream.iter_s Lwt_io.printl but that ends up hanging indefinitely. |
The proposed type signature would capture the behavior of |
The code using the stream does not and should not know about this failure state. That said, I'm not sure how to properly capture this failure in a sane way since this hangs rather than capturing the error as I would have expected it to. Do you have any suggestions for a better approach? |
Ok, then this needs to be addressed. In the I guess the specific effect you seem to be trying to achieve can be solved with an In the meantime: open Lwt.Infix
let until_map : ('a -> 'b option) -> 'a Lwt_stream.t -> 'b Lwt_stream.t =
fun f s ->
Lwt_stream.from (fun () ->
Lwt_stream.get s >|= function
| None -> None
| Some v -> f v)
let () =
Lwt_unix.files_of_directory "/"
|> Lwt_stream.map_exn
|> until_map (function
| Lwt_stream.Value v -> Some v
| Lwt_stream.Error _ -> None)
|> Lwt_stream.iter_s Lwt_io.printl
|> Lwt_main.run I want to leave this issue open as an example of the kind of things that need to be considered when working on
|
Closing this issue as there is a fairly reasonable solution. For current Lwt, in the above code, Also, |
Related ocsigen#265. [skip ci]
I'm not sure how to handle this kind of failure in Lwt's current state (2.5.2) since it happens in the generation of the stream, presumably on
lwt/src/unix/lwt_unix.ml
Line 1078 in 7ff9808
One change would be to open the directory before returning the stream, changing the type to:
or add a new function with the new signature.
Example of the failure from utop:
The text was updated successfully, but these errors were encountered: