Real-Serious-Games / C-Sharp-Promise

Promises library for C# for management of asynchronous operations.
MIT License
1.2k stars 149 forks source link

Added Promise<T>.First() to find the first promise that returns a value. #99

Closed alonsohki closed 5 years ago

RoryDungan commented 5 years ago

Looks cool but isn't this the same functionality as Promise.Race?

alonsohki commented 5 years ago

Not exactly. Race() is the first of All(), while First() is the first of Sequence().

alonsohki commented 5 years ago

This is how I am using it, which is a good use case:

            ResolveDNS(server)
                .Then(entry =>
                {
                    var requests = from address in entry.AddressList
                                   select new Func<IPromise<double>>(() => GetNTPTime(address));
                    return Promise<double>.First(requests);
                })

It takes a list of addresses that a host resolves to, and returns the first one that works (in case one of them doesn't work, times out, or raises any other issue).

alonsohki commented 5 years ago

Is there any reason why this isn't being approved?

RoryDungan commented 5 years ago

@Borningstar or @kalvinpearce can you take a look at this?