You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The iterator interface is a powerful mechanism for encapsulating lazy extraction from an external data source. In its current form there is an asymmetry between when server side resources can be requested (in "start"), and when server side resources can be released (manually after loop completion). To address this an optional "stop method" could be added that is automatically run on all forms of loop exit.
In particular putting an iterable reader of an external resource into a comprehension requires following that comprehension with some form of signal to the external data source to release server side resources.
The chief concern is that the caller of the iterable interface has no knowledge of any external resources that would have been requested during "start", and would find those variables to be inaccessible at the end of iteration (at least without making a potentially error generating call to "next").
Example Use Case
Consider a type that encapsulates an iterable connection to a data source (e.g. the classic forward only data reader)
immutable DataReader <: AbstractIterableConnections
...
end
To implement the iterations we would overload in the following manner
start(x::DataReader)
...
state = newservercursor(DataReader)
...
state
end
next(x::DataReader, s::cursor)
...
y = read!(s)
...
(y, s)
end
done(x::DataReader, s::cursor) = x.closed || s.eof
stop(x::DataReader, s::cursor)
...
releaseresources!(s)
...
end
Where the default definition of stop is given by
stop(::Any, ::Any) = nothing
The text was updated successfully, but these errors were encountered:
Proposal
The iterator interface is a powerful mechanism for encapsulating lazy extraction from an external data source. In its current form there is an asymmetry between when server side resources can be requested (in "start"), and when server side resources can be released (manually after loop completion). To address this an optional "stop method" could be added that is automatically run on all forms of loop exit.
In particular putting an iterable reader of an external resource into a comprehension requires following that comprehension with some form of signal to the external data source to release server side resources.
The chief concern is that the caller of the iterable interface has no knowledge of any external resources that would have been requested during "start", and would find those variables to be inaccessible at the end of iteration (at least without making a potentially error generating call to "next").
Example Use Case
Consider a type that encapsulates an iterable connection to a data source (e.g. the classic forward only data reader)
To implement the iterations we would overload in the following manner
Where the default definition of stop is given by
The text was updated successfully, but these errors were encountered: