Re: [elixir-core:10184] Proposal: Add function to return the first async task to complete

2021-03-31 Thread Thiago Santos
+1 for yield_first(tasks, n, timeout) It seems to better convey the meaning "yield the first n tasks". Em qua., 31 de mar. de 2021 às 19:26, Felipe Stival escreveu: > +1 for yield_first(tasks, n, timeout) > > > On Thu, Apr 1, 2021, 01:11 José Valim wrote: > >> It was not possible to implement

Re: [elixir-core:10183] Proposal: Add function to return the first async task to complete

2021-03-31 Thread Felipe Stival
+1 for yield_first(tasks, n, timeout) On Thu, Apr 1, 2021, 01:11 José Valim wrote: > It was not possible to implement yield_first in Elixir but now that we > have map_get in guards, we can easily do so by putting all refs in a map > and only getting messages from the inbox where the ref is in

Re: [elixir-core:10182] Proposal: Add function to return the first async task to complete

2021-03-31 Thread José Valim
It was not possible to implement yield_first in Elixir but now that we have map_get in guards, we can easily do so by putting all refs in a map and only getting messages from the inbox where the ref is in the map. The number of tasks to wait and the maximum timeout should be configurable too. For

Re: [elixir-core:10182] Proposal: Add function to return the first async task to complete

2021-03-31 Thread thia.md...@gmail.com
I think the proposal would work differently from yield_many. yield_many "receives a list of tasks and waits for their replies in the given time interval". The proposal of the new function is to return as soon as the first task finishes. For example, if we start tasks to make call to 3

Re: [elixir-core:10180] Proposal: Add function to return the first async task to complete

2021-03-31 Thread Wojtek Mach
Check out Task.yield_many/2 (https://hexdocs.pm/elixir/Task.html#yield_many/2 ) :-) > On 31 Mar 2021, at 22:54, thia.md...@gmail.com > wrote: > > Proposal > > Add a function to the Task module that takes a list of tasks, and returns as >

[elixir-core:10180] Proposal: Add function to return the first async task to complete

2021-03-31 Thread thia.md...@gmail.com
*Proposal* Add a function to the Task module that takes a list of tasks, and returns as soon as one of the tasks finishes, shuting down the other tasks. The behaviour would pretty similar to what Javascript have with Promise.any