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

Allow queue to be used for task finished. #276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Aug 30, 2023

#!/usr/bin/env ruby

require_relative 'lib/async'
require_relative 'lib/async/queue'

Async do
  queue = Async::Queue.new
  
  10.times do |i|
    Async(finished: queue) do
      # raise "Boom" if rand > 0.5
      sleep(i)
    end
  end
  
  queue.each do |task|
    puts task.wait
  end
end

However, it's not clear how to close the queue to indicate no more jobs will be added.

@emiltin
Copy link
Contributor

emiltin commented Sep 7, 2023

I'm sure I understand how this would be used to make a barrier fail fast in case a task fail, as discussed in #272.

Is the idea that all tasks in the barrier would use the same condition to signal when they are done, so that the barrier will be notified when a task finish, and potentially fail fast? I think that would have the side effect that if some other code wait for a particular task in the barrier, then that wait would end whenever any task in the barrier finishes?

@emiltin
Copy link
Contributor

emiltin commented Sep 11, 2023

However, it's not clear how to close the queue to indicate no more jobs will be added.

What about a drain method, which works like each, except it returns as soon as the queue is empty?

@emiltin
Copy link
Contributor

emiltin commented Sep 12, 2023

What about a drain method, which works like each, except it returns as soon as the queue is empty?

To clarify - this would imply that tasks are added to the queue when created, and are removed when they finish. drain would yield each task as they complete, returning when there is no more items.

The current PR works differently: it adds task to the queue only when finished. each waits for new items to be added, which are then removed and yielded. It never returns.

@ioquatix
Copy link
Member Author

I have not had time to revisit this yet, but I will in the coming week.

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

Successfully merging this pull request may close these issues.

None yet

2 participants