* [Caml-list] Is there a way to abort Stream.iter ?
@ 2017-05-12 14:34 Jon Kleiser
2017-05-13 12:24 ` Yaron Minsky
0 siblings, 1 reply; 3+ messages in thread
From: Jon Kleiser @ 2017-05-12 14:34 UTC (permalink / raw)
To: caml-list
In my little program here <http://folk.uio.no/jkleiser/ocaml/read_vec.ml> I’m reading and processing a text file by doing this:
let process_lines lines =
let start_time = Sys.time () in
Stream.iter process_line lines;
let finish_time = Sys.time () in
Printf.printf "\nTime used: %f secs\n" (finish_time -. start_time)
. . . where the ‘lines’ input is coming from ‘(line_stream_of_channel in_channel)’.
Is there a way to abort the Stream.iter processing based on some condition detected by the ‘process_line’ function? Could it be done by throwing an exception? Maybe I should use something else than Stream.iter ?
/Jon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Is there a way to abort Stream.iter ?
2017-05-12 14:34 [Caml-list] Is there a way to abort Stream.iter ? Jon Kleiser
@ 2017-05-13 12:24 ` Yaron Minsky
2017-05-13 12:25 ` Yaron Minsky
0 siblings, 1 reply; 3+ messages in thread
From: Yaron Minsky @ 2017-05-13 12:24 UTC (permalink / raw)
To: Jon Kleiser; +Cc: caml-list
First of all, you should probably use a Pipe.t rather than a Stream.t.
Streams don't provide you with a way of pushing back, meaning the
process that's filling data into the Stream won't slow down if you're
slow in draining data from it. Pipes give you a mechanism for doing
this, in that a Pipe has a bounded amount of slack.
For pipes, when I want to control the exit time, I'll typically do a
recursive loop using Pipe.read or Pipe.read'. You can do something
similar with streams.
y
On Fri, May 12, 2017 at 10:34 AM, Jon Kleiser <jon.kleiser@ceres.no> wrote:
> In my little program here <http://folk.uio.no/jkleiser/ocaml/read_vec.ml> I’m reading and processing a text file by doing this:
>
> let process_lines lines =
> let start_time = Sys.time () in
> Stream.iter process_line lines;
> let finish_time = Sys.time () in
> Printf.printf "\nTime used: %f secs\n" (finish_time -. start_time)
>
> . . . where the ‘lines’ input is coming from ‘(line_stream_of_channel in_channel)’.
>
> Is there a way to abort the Stream.iter processing based on some condition detected by the ‘process_line’ function? Could it be done by throwing an exception? Maybe I should use something else than Stream.iter ?
>
> /Jon
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Is there a way to abort Stream.iter ?
2017-05-13 12:24 ` Yaron Minsky
@ 2017-05-13 12:25 ` Yaron Minsky
0 siblings, 0 replies; 3+ messages in thread
From: Yaron Minsky @ 2017-05-13 12:25 UTC (permalink / raw)
To: Jon Kleiser; +Cc: caml-list
Also, as you can see here:
https://github.com/janestreet/async_kernel/blob/master/src/pipe.mli#L525
Pipe.iter and Pipe.iter' will terminate if the callback throws.
y
On Sat, May 13, 2017 at 8:24 AM, Yaron Minsky <yminsky@janestreet.com> wrote:
> First of all, you should probably use a Pipe.t rather than a Stream.t.
> Streams don't provide you with a way of pushing back, meaning the
> process that's filling data into the Stream won't slow down if you're
> slow in draining data from it. Pipes give you a mechanism for doing
> this, in that a Pipe has a bounded amount of slack.
>
> For pipes, when I want to control the exit time, I'll typically do a
> recursive loop using Pipe.read or Pipe.read'. You can do something
> similar with streams.
>
> y
>
> On Fri, May 12, 2017 at 10:34 AM, Jon Kleiser <jon.kleiser@ceres.no> wrote:
>> In my little program here <http://folk.uio.no/jkleiser/ocaml/read_vec.ml> I’m reading and processing a text file by doing this:
>>
>> let process_lines lines =
>> let start_time = Sys.time () in
>> Stream.iter process_line lines;
>> let finish_time = Sys.time () in
>> Printf.printf "\nTime used: %f secs\n" (finish_time -. start_time)
>>
>> . . . where the ‘lines’ input is coming from ‘(line_stream_of_channel in_channel)’.
>>
>> Is there a way to abort the Stream.iter processing based on some condition detected by the ‘process_line’ function? Could it be done by throwing an exception? Maybe I should use something else than Stream.iter ?
>>
>> /Jon
>>
>> --
>> Caml-list mailing list. Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-13 12:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-12 14:34 [Caml-list] Is there a way to abort Stream.iter ? Jon Kleiser
2017-05-13 12:24 ` Yaron Minsky
2017-05-13 12:25 ` Yaron Minsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox