Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isempty(itr) consumes the outputs of tasks and discards them #6447

Closed
micklat opened this issue Apr 7, 2014 · 1 comment
Closed

isempty(itr) consumes the outputs of tasks and discards them #6447

micklat opened this issue Apr 7, 2014 · 1 comment

Comments

@micklat
Copy link
Contributor

micklat commented Apr 7, 2014

Consider this code:


function p()
    produce(1)
    produce(2) 
end

t = Task(p)

for i in 1:10
    assert(!isempty(t))
end

With Julia commit 2990c29, this fails in the third iteration, because isempty consumes the task's outputs (which seems unusal for isempty(), IMO).

The isempty method that gets called is the one in iterator.jl:

isempty(itr) = done(itr, start(itr))

I do not know enough to comment on whether or not this implementation is appropriate for tasks.

One would expect isempty() to avoid modifying its argument, or at least to avoid observable modifications. I don't think isempty() is very useful when it consumes outputs - the caller probably has something to do with those outputs, and would not like to discard them. So unless I'm missing the intended usage, I suggest that isempty() either should not exist for tasks, or (better) that there would be some 'look-ahead' buffer in the task so that isempty can store the consumed element there, rather than discard it. I realize that doing so might be a nontrivial modification.

@ivarne
Copy link
Member

ivarne commented Apr 7, 2014

Cross linking first report: https://groups.google.com/forum/m/#!topic/julia-users/fErvAG45yt8

tanmaykm added a commit to tanmaykm/julia that referenced this issue Apr 7, 2014
tanmaykm added a commit to tanmaykm/julia that referenced this issue Apr 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants