ruby-concurrency / ruby-concurrency/concurrent-ruby
Support Hash of Futures for Promises.zip
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 5.8k
- Forks
- 420
- Ø Merge
- 20 Std. 45 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
Reading the guide for the Promises work in 1.1.x I came across the fantastic Concurrent::Promises.zip method.
It's interface, per the guide, expects an array of Futures and will return a final value of said array's values. This is beneficial, but what would make my (and I suspect many other's) code cleaner is to optionally accept a Hash of promises instead of an Array.
e.g.
map_of_work = {
multiply: Concurrent::Promises.future { 3*2 },
divide: Concurrent::Promises.future { 3/2 },
add: Concurrent::Promises.future { 3 + 2 },
subtract: Concurrent::Promises.future { 3 - 2 },
}
# => {:multiply=>#<Concurrent::Promises::Future:0x00007fc474fad8a0 pending>,
# :divide=>#<Concurrent::Promises::Future:0x00007fc474fad008 pending>,
# :add=>#<Concurrent::Promises::Future:0x00007fc474fa7d60 pending>,
# :subtract=>#<Concurrent::Promises::Future:0x00007fc474fa6ca8 pending>}
Concurrent::Promises.zip(map_of_work).value!
# => {:multiply=>6,
# :divide=>1,
# :add=>5,
# :subtract=>1}
Why? Because it's a common pattern in Javascript libraries[1][2], and thus my team.
Arrays are slightly more cumbersome where I have to remember that index 2 is always for the addition work. Should another developer prepend more Futures to the array, we must not forget to change all the indexes referenced thereafter. With hashes, an :add is always an :add.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
The entry point is Concurrent::Promises.zip; start by reading its current array-oriented behavior and the linked Promises guide. Support the shown hash-of-promises input while preserving keys and resolving values, then confirm the example returns the expected keyed result.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100