An open API service indexing awesome lists of open source software.

https://github.com/nagilum/promise

C# Promise
https://github.com/nagilum/promise

Last synced: 3 months ago
JSON representation

C# Promise

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()
```