ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
@ 2020-11-15 22:06 chris
  2020-11-15 22:07 ` [ruby-core:100859] " chris
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: chris @ 2020-11-15 22:06 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been reported by chrisseaton (Chris Seaton).

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100859] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
@ 2020-11-15 22:07 ` chris
  2020-11-15 22:11 ` [ruby-core:100860] " samuel
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: chris @ 2020-11-15 22:07 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by chrisseaton (Chris Seaton).


https://github.com/ruby/ruby/pull/3768

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88503

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100860] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
  2020-11-15 22:07 ` [ruby-core:100859] " chris
@ 2020-11-15 22:11 ` samuel
  2020-11-15 22:13 ` [ruby-core:100861] " chris
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: samuel @ 2020-11-15 22:11 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by ioquatix (Samuel Williams).


What about a way to bulk add items, and maybe it would be best to have the first argument as an array, e.g. `Queue.new(worklist)`? I think it's more expensive to expand it in CRuby when you write `*worklist`.

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88504

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100861] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
  2020-11-15 22:07 ` [ruby-core:100859] " chris
  2020-11-15 22:11 ` [ruby-core:100860] " samuel
@ 2020-11-15 22:13 ` chris
  2020-11-15 22:50 ` [ruby-core:100862] " samuel
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: chris @ 2020-11-15 22:13 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by chrisseaton (Chris Seaton).


I'm not worried about `Queue.new(worklist)` or `Queue.new(*worklist)`, so that's fine if more people feel that way. I think the key thing is conciseness in text source code, and also avoiding needing to synchronise while adding each individual item.

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88505

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100862] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (2 preceding siblings ...)
  2020-11-15 22:13 ` [ruby-core:100861] " chris
@ 2020-11-15 22:50 ` samuel
  2020-11-16  9:11 ` [ruby-core:100870] " jean.boussier
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: samuel @ 2020-11-15 22:50 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by ioquatix (Samuel Williams).


That all makes sense to me.

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88506

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100870] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (3 preceding siblings ...)
  2020-11-15 22:50 ` [ruby-core:100862] " samuel
@ 2020-11-16  9:11 ` jean.boussier
  2020-11-16 12:12 ` [ruby-core:100871] " ufuk
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jean.boussier @ 2020-11-16  9:11 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by byroot (Jean Boussier).


I agree that the constructor should take an enumerable rather than variadic arguments, as it would be consistent with `Set.new([1, 2, 3])`, and `Array.new([1, 2, 3])`

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88517

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:100871] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (4 preceding siblings ...)
  2020-11-16  9:11 ` [ruby-core:100870] " jean.boussier
@ 2020-11-16 12:12 ` ufuk
  2020-12-09 11:04 ` [ruby-core:101339] " chris
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ufuk @ 2020-11-16 12:12 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by ufuk (Ufuk Kayserilioglu).


Agreed with @byroot (actually I was going to note the same, he beat me to it). 

I would also like to note that different from `Set`, for example, the order of items in the supplied parameter matters in the `Queue` case. Even though the expected outcome is for the items to be `push`ed to the `Queue` in given order, it might still be a good idea to explicitly call that out in the method documentation.

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-88518

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:101339] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (5 preceding siblings ...)
  2020-11-16 12:12 ` [ruby-core:100871] " ufuk
@ 2020-12-09 11:04 ` chris
  2021-01-13  6:05 ` [ruby-core:102050] " matz
  2021-01-29  8:50 ` [ruby-core:102290] " ko1
  8 siblings, 0 replies; 10+ messages in thread
From: chris @ 2020-12-09 11:04 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by chrisseaton (Chris Seaton).


I updated to take a single array rather than a variable number of arguments.

I had two choices for how to do this - `Set` takes an `Enumerable`, using `each` to access items, and `Array` takes another `Array`, using `#to_ary` if needed.

I went with the same as what `Array` does, because both `Array` and `Queue` are core libraries, where `Set` is a standard library.

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-89039

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:102050] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (6 preceding siblings ...)
  2020-12-09 11:04 ` [ruby-core:101339] " chris
@ 2021-01-13  6:05 ` matz
  2021-01-29  8:50 ` [ruby-core:102290] " ko1
  8 siblings, 0 replies; 10+ messages in thread
From: matz @ 2021-01-13  6:05 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by matz (Yukihiro Matsumoto).


I accept the idea. Take `Enumerable` as initial values.

Matz.


----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-89906

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:102290] [Ruby master Feature#17327] The Queue constructor should take an initial set of items
  2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
                   ` (7 preceding siblings ...)
  2021-01-13  6:05 ` [ruby-core:102050] " matz
@ 2021-01-29  8:50 ` ko1
  8 siblings, 0 replies; 10+ messages in thread
From: ko1 @ 2021-01-29  8:50 UTC (permalink / raw)
  To: ruby-core

Issue #17327 has been updated by ko1 (Koichi Sasada).

Assignee set to ko1 (Koichi Sasada)

----------------------------------------
Feature #17327: The Queue constructor should take an initial set of items
https://bugs.ruby-lang.org/issues/17327#change-90145

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
----------------------------------------
I often create a `Queue` and then process it with a set of concurrent workers in threads. I end up writing:

```ruby
q = Queue.new
worklist.each do |work|
  q.push work
end
```

I'd rather be able to write

```ruby
q = Queue.new(*worklist)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-01-29  8:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15 22:06 [ruby-core:100858] [Ruby master Feature#17327] The Queue constructor should take an initial set of items chris
2020-11-15 22:07 ` [ruby-core:100859] " chris
2020-11-15 22:11 ` [ruby-core:100860] " samuel
2020-11-15 22:13 ` [ruby-core:100861] " chris
2020-11-15 22:50 ` [ruby-core:100862] " samuel
2020-11-16  9:11 ` [ruby-core:100870] " jean.boussier
2020-11-16 12:12 ` [ruby-core:100871] " ufuk
2020-12-09 11:04 ` [ruby-core:101339] " chris
2021-01-13  6:05 ` [ruby-core:102050] " matz
2021-01-29  8:50 ` [ruby-core:102290] " ko1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).