File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,22 @@ defprotocol Collectable do
6969 iex> Enum.into([1, 2, 3], MapSet.new())
7070 MapSet.new([1, 2, 3])
7171
72+ ## Halting
73+
74+ The `:halt` flag will be given whenever the collection won't
75+ terminate correctly and must be used to clean up existing resources
76+ (such as sockets, file handles, etc).
77+
78+ Note it is not guaranteed that the accumulator given to halt will
79+ be the latest version of the accumulator returned by a previous call
80+ with `{:cont, elem}`. Therefore, you must track the collected results
81+ within the resource you intend to halt.
82+
83+ This is by design: ensuring halt is always called with the latest
84+ accumulator would make pure collectables (the ones that do not implement
85+ halt) expensive. However, given the collectables that must implement halt
86+ already need to track state, the burden of tracking the accumulator
87+ across invocations is put on them.
7288 """
7389
7490 @ type command :: { :cont , term } | :done | :halt
You can’t perform that action at this time.
0 commit comments