mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-03-09 23:23:35 -04:00
doc(IO): explain lifetime of gen a bit
This commit is contained in:
parent
11d081a612
commit
edcd97a7ed
1 changed files with 18 additions and 1 deletions
|
|
@ -21,7 +21,7 @@
|
||||||
with_in "/tmp/input"
|
with_in "/tmp/input"
|
||||||
(fun ic ->
|
(fun ic ->
|
||||||
let chunks = read_chunks ic in
|
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 ->
|
(fun oc ->
|
||||||
write_gen oc chunks
|
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
|
@since 0.6
|
||||||
|
|
||||||
@before 0.12 was in 'containers.io', now moved into 'containers'
|
@before 0.12 was in 'containers.io', now moved into 'containers'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue