mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
23 lines
448 B
Markdown
23 lines
448 B
Markdown
---
|
|
date: 20201111
|
|
id: e059aba7-2912-4a54-8c04-dbb6fbd3d0a7
|
|
title: Producing Promises
|
|
---
|
|
|
|
# Advice
|
|
|
|
Use [Async functions](20201026103714-javascript_async_functions) instead
|
|
of this.
|
|
|
|
# Syntax
|
|
|
|
``` javascript
|
|
const p = new Promise(
|
|
function (resolve, reject) { // (A)
|
|
if (true /* replace true with your own logic */) {
|
|
resolve(value); // success
|
|
} else {
|
|
reject(reason); // failure
|
|
}
|
|
});
|
|
```
|