caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Raphael Proust <raphlalou@gmail.com>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Lwt idioms: iterating
Date: Wed, 23 Jan 2013 10:15:37 +0000	[thread overview]
Message-ID: <CAAmHUAn_HhYS=5_W_6DiNv5gjbMoGYUMAZLsg-2Z6jj2Yaye3Q@mail.gmail.com> (raw)
In-Reply-To: <87pq0w4hlh.fsf@golf.niidar.ru>

On Wed, Jan 23, 2013 at 5:02 AM, Ivan Gotovchits <ivg@ieee.org> wrote:
>
> What is a best practice to implement a common iterative operations with
> Lwt?
>
> For example, I have a data structure incapsulating some
> collection. Interface of the structure includes some iterators, i.e.
>
>   val iter (e -> unit) -> t -> unit
>
>
> Now, I would like to output each element of type e using one of the
> functions from Lwt_io module.
>
> I see two solutions and neither I like:
>
> 1. Use Buffer.t to accumulate text while iterating, then output it.
>
> 2. Use Lwt_stream.t for the same purpose.

3. Just write it directly and trust the Lwt scheduler to flush the write buffer.

The page https://ocsigen.org/lwt/api/Lwt_io explains that writes are
automatically flushed ``when there is nothing else to do''

~~~~~~~
If you are familiar with buffered channels you may be familiar too
with the flush operation. Note that byte channles of this
modules are automatically flushed when there is nothing else to do
(i.e. before the program goes into idle), so this means that you
no longer have to write:

eprintf "log message\n";
      flush stderr;

to have you messages displayed.
~~~~~~~

>
> Both solutions a rather imperative and too ad-hoc (not scales to other
> iterators and tasks).
>
> Are there any idiomatic solutions for such common tasks in Lwt?
>
> --
>          (__)
>          (oo)
>    /------\/
>   / |    ||
>  *  /\---/\
>     ~~   ~~
> ...."Have you mooed today?"...
>
> --
> 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



-- 
______________
Raphaël Proust

      reply	other threads:[~2013-01-23 10:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-23  5:02 Ivan Gotovchits
2013-01-23 10:15 ` Raphael Proust [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAmHUAn_HhYS=5_W_6DiNv5gjbMoGYUMAZLsg-2Z6jj2Yaye3Q@mail.gmail.com' \
    --to=raphlalou@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=ivg@ieee.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).