https://github.com/kartikmehta8/pact-custom-promise
Pact is a custom implementation of JavaScript's Promise. The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
https://github.com/kartikmehta8/pact-custom-promise
implementation javascript promise
Last synced: 3 months ago
JSON representation
Pact is a custom implementation of JavaScript's Promise. The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
- Host: GitHub
- URL: https://github.com/kartikmehta8/pact-custom-promise
- Owner: kartikmehta8
- Created: 2022-12-02T15:19:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-02T15:52:03.000Z (over 2 years ago)
- Last Synced: 2025-01-16T05:55:21.068Z (4 months ago)
- Topics: implementation, javascript, promise
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![]()
# Promise
A JavaScript Promise object contains both the producing code and calls to the consuming code:```javascript
let myPromise = new Promise(function(myResolve, myReject) {
// "Producing Code" (May take some time)myResolve(); // when successful
myReject(); // when error
});// "Consuming Code" (Must wait for a fulfilled Promise)
myPromise.then(
function(value) { /* code if successful */ },
function(error) { /* code if some error */ }
);
```When the producing code obtains the result, it should call one of the two callbacks:
| **Result** | **Call** |
| -------------|--------------------------|
| Success | myResolve(result value) |
| Error | myReject(error object) |# Promise Object Properties
A JavaScript Promise object can be:
- Pending
- Fulfilled
- RejectedThe Promise object supports two properties: **state** and **result**.
While a Promise object is "pending" (working), the result is undefined.
When a Promise object is "fulfilled", the result is a value.
When a Promise object is "rejected", the result is an error object.
| **myPromise.state** | **myPromise.result** |
|---------------------|----------------------|
| "pending" | undefined |
| "fulfilled" | a result value |
| "rejected" | an error object |### Pact is a custom implementation of JavaScript's Promise.