Real-Serious-Games / C-Sharp-Promise

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

Feature Request: Promise retry #100

Closed jurasans closed 4 years ago

jurasans commented 5 years ago

hi,

feature request here : this library does not possess the ability to retry a promise. i would very much like to see that kind of functionality being added

CSparn commented 4 years ago

Hi, I'm also looking for a possibilty to retry or reuse a promise. Maybe by resetting the state? Or is there a description anywhere how to initialize a new Promise with the function of a already rejected promise? Greetings

Found a workaround by looking in the code! You can initialize the Promise with an Action object. In this object you can define the used function. With this action object you can initialze multiple Promises with the same function code.

Example:

` Action<Action, Action> func = (resolve, reject) => { try: { // Do calculations here int result = 10;

              // return calculated value
             resolve(result);
          }
          catch(Exception ex)
          {
           reject(ex);
          }
        };

Promise promise = new Promise(func); Promise repeatPromise = new Promise(func); `

Arvtesh commented 4 years ago

You cannot reset state of a promise. I don't think any promise implementation supports this. And for a good reason.

You have to create new promise each time. Exactly like you did.