mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 21:16:21 +00:00
39 lines
1 KiB
Markdown
39 lines
1 KiB
Markdown
---
|
|
date: 2020-09-11
|
|
id: 14e0ce4b-b4b1-46fe-946a-c519550682ac
|
|
title: JavaScript Promises
|
|
---
|
|
|
|
# Introduction
|
|
|
|
A Promise[^1] is an asynchronous action that may complete at some point
|
|
and produce a value. It is able to notify anyone who is interested when
|
|
its value is available.
|
|
|
|
``` javascript
|
|
let fifteen = Promise.resolve(15);
|
|
fifteen.then(value => console.log(`Got ${value}`))
|
|
```
|
|
|
|
# Parallel
|
|
|
|
- [Executing Promises in Parallel
|
|
(Promises.all)](20201111094957-executing_promises_in_parallel_promises_all)
|
|
- [Promise.allSettled](20201116163327-promise_allsettled)
|
|
|
|
# Errors
|
|
|
|
- [Catching Promise Errors](20201111095100-catching_promise_errors)
|
|
- [Finally](20201111095454-javascript_promises_finally)
|
|
|
|
# Producing & Consuming
|
|
|
|
Use [Async functions](20201026103714-javascript_async_functions) instead
|
|
of this.
|
|
|
|
- [Producing Promises](20201111095230-producing_promises)
|
|
- [Consuming Promises](20201111095316-javascript_consuming_promises)
|
|
|
|
# Footnotes
|
|
|
|
[^1]: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>
|