doc(IO): explain lifetime of gen a bit

This commit is contained in:
Simon Cruanes 2019-11-08 11:27:01 -06:00
parent 11d081a612
commit edcd97a7ed

View file

@ -21,7 +21,7 @@
with_in "/tmp/input"
(fun ic ->
let chunks = read_chunks ic in
with_out ~flags:[Open_binary] ~mode:0o644 "/tmp/output"
with_out ~flags:[Open_binary; Open_creat] ~mode:0o644 "/tmp/output"
(fun oc ->
write_gen oc chunks
)
@ -29,6 +29,23 @@
) ;;
]}
- Note that the lifetime of an IO generator is tied to the underlying
channel. In the example above, [chunks] must be used in the scope of [ic].
This will raise an error:
{[
# CCIO.(
let chunks =
with_in "/tmp/input"
(fun ic ->read_chunks ic)
in
with_out ~flags:[Open_binary;Open_creat] ~mode:0o644 "/tmp/output"
(fun oc ->
write_gen oc chunks
)
) ;;
]}
@since 0.6
@before 0.12 was in 'containers.io', now moved into 'containers'