Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 302fc4e

Browse files
Merge pull request #7 from jeffreylanters/feature/async-await
Feature/async await
2 parents e49d54f + d3ab940 commit 302fc4e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ openupm add nl.elraccoone.promises
5151

5252
# Documentation
5353

54-
## Syntax
55-
56-
```cs
57-
new Promise ((resolve, reject) => { /* ... */ });
58-
new Promise<ResolveType> ((resolve, reject) => { /* ... */ });
59-
new Promise<ResolveType, RejectType> ((resolve, reject) => { /* ... */ });
60-
```
61-
62-
A function that is passed with the arguments resolve and reject. The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise, respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve function to resolve the promise or else rejects it if an error occurred. If an error is thrown in the executor function, the promise is rejected. The return value of the executor is ignored.
63-
64-
## Description
65-
6654
A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.
6755

6856
A Promise is in one of these states:
@@ -73,6 +61,16 @@ A Promise is in one of these states:
7361

7462
A pending promise can either be fulfilled with a value, or rejected with a reason (error). When either of these options happens, the associated handlers queued up by a promise's then method are called. (If the promise has already been fulfilled or rejected when a corresponding handler is attached, the handler will be called, so there is no race condition between an asynchronous operation completing and its handlers being attached.)
7563

64+
## Syntax
65+
66+
A function that is passed with the arguments resolve and reject. The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise, respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve function to resolve the promise or else rejects it if an error occurred. If an error is thrown in the executor function, the promise is rejected. The return value of the executor is ignored.
67+
68+
```cs
69+
new Promise ((resolve, reject) => { /* ... */ });
70+
new Promise<ResolveType> ((resolve, reject) => { /* ... */ });
71+
new Promise<ResolveType, RejectType> ((resolve, reject) => { /* ... */ });
72+
```
73+
7674
## Creating a Promise
7775

7876
A Promise object is created using the new keyword and its constructor. This constructor takes as its argument a function, called the "executor function". This function should take two functions as parameters. The first of these functions (resolve) is called when the asynchronous task completes successfully and returns the results of the task as a value. The second (reject) is called when the task fails, and returns the reason for failure, which is typically an error object.
@@ -121,7 +119,7 @@ public void Start () {
121119
}
122120
```
123121

124-
### Using Async/Await method
122+
### Using Async/Await methods
125123

126124
When chaining multiple promises after one another or when simply wanting to prevent a lot of nested callbacks, use the async await logic to keep things simple. There are two ways of doing so, the simplest way does not require any changes on the promise's creation side. A basic implementation could be as following.
127125

0 commit comments

Comments
 (0)