Boost logo

Boost :

Subject: Re: [boost] [afio] Formal review of Boost.AFIO
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2015-08-27 00:33:09


On 27/08/2015 14:16, Niall Douglas wrote:
>> So just for clarity, this does mean that the file will not be deleted in
>> that example (in case of earlier error), yes?
>
> In the sequence:
>
> auto a=async_file();
> auto b=async_read(a);
> auto c=async_truncate(b);
> auto d=async_rmfile(c);
> auto e=async_close(d);
>
> ... you are explicitly saying do not execute later steps if an
> earlier step fails. It defaults to this as this is probably safest
> and least surprising.

Agreed, that's what I was expecting.

> If on the other hand you DO always want to delete and close the file
> no matter what happened before you would write:
>
> auto a=async_file();
> auto b=async_read(a);
> auto c=async_truncate(b);
> auto d=async_rmfile(depends(c, a));
> auto e=async_close(d);
>
> The depends(precondition, input) function swaps the second future for
> the first when the first completes. It is implemented as:
>
> precondition.then([input](future &&f) { return input; }

That's handy but possibly a little unobvious (not that I can think of a
better way to do it at the moment).

(Also, what happens if the passed/returned future isn't ready yet? Does
the caller cascade the wait / re-register itself as a continuation? Or
is that an error?)

> It occurs to me that the above is exactly what should be on a first
> page of a tutorial. To be honest, it never occurred to me the above
> wasn't totally obvious. So I've logged that to
> https://github.com/BoostGSoC13/boost.afio/issues/97.
>
> Thanks Gavin.

Sounds good.

I know error-checking is often elided from examples for brevity, but it
does seem like it needs covering somewhere. Although I'm also being a
bit nit-picky, admittedly.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk