https://github.com/nagilum/promise
C# Promise
https://github.com/nagilum/promise
Last synced: 4 months ago
JSON representation
C# Promise
- Host: GitHub
- URL: https://github.com/nagilum/promise
- Owner: nagilum
- Created: 2017-10-02T19:49:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T07:39:20.000Z (about 8 years ago)
- Last Synced: 2025-03-06T03:16:57.723Z (8 months ago)
- Language: C#
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Promise
C# Promise-like library
Yes it handles promises within promises.
## Async Call
```csharp
var promise = new Promise()
.Then(GetPersonList)
.Then, List>(GetPersonsAges)
.Then, int>(CombineAges)
.Catch(HandleNullReferenceException)
.Catch(HandleException)
.ExecuteAsync();
while (promise.IsRunning) {
Task.Delay(1);
}
var age = promise.CastTo();
```
## Sync Call
```csharp
var age = new Promise()
.Then(GetPersonList)
.Then, List>(GetPersonsAges)
.Then, int>(CombineAges)
.Catch(HandleNullReferenceException)
.Catch(HandleException)
.Execute()
.CastTo();
```
## Use Lambda functions
```csharp
var age = new Promise()
.Then(() => new Dictionary {
{"Barack Obama", 56},
{"Albert Einstein", 76}
})
.Then((Dictionary persons) => {
return persons.Sum(p => p.Value);
})
.Execute()
.CastTo();
```
## Properties
```csharp
// Indicates whether or not the promise is still executing.
bool IsRunning
// Output of the last function.
object Result
```
## Helper functions
```csharp
// Attempt to cast the Result to given type.
CastTo()
// Wait for the promise to finish executing.
Wait()
```