images to svg
|
@ -38,7 +38,7 @@ When the executor finishes the job, it should call one of the functions that it
|
|||
- sets `state` to `"rejected"`,
|
||||
- sets `result` to `error`.
|
||||
|
||||

|
||||

|
||||
|
||||
Later we'll see how these changes become known to "fans".
|
||||
|
||||
|
@ -60,7 +60,7 @@ We can see two things by running the code above:
|
|||
|
||||
After one second of "processing" the executor calls `resolve("done")` to produce the result:
|
||||
|
||||

|
||||

|
||||
|
||||
That was an example of a successful job completion, a "fulfilled promise".
|
||||
|
||||
|
@ -73,7 +73,7 @@ let promise = new Promise(function(resolve, reject) {
|
|||
});
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
To summarize, the executor should do a job (something that takes time usually) and then call `resolve` or `reject` to change the state of the corresponding Promise object.
|
||||
|
||||
|
|
Before Width: | Height: | Size: 13 KiB |
27
1-js/11-async/02-promise-basics/promise-reject-1.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="512px" height="106px" viewBox="0 0 512 106" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>promise-reject-1.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="promise" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="promise-reject-1.svg">
|
||||
<path d="M9,34 L9,92 L184,92 L184,34 L9,34 Z" id="Rectangle-1" stroke="#E8C48E" stroke-width="2" fill="#FFF9EB"></path>
|
||||
<text id="new-Promise(executor" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#707175">
|
||||
<tspan x="10" y="22">new Promise(executor)</tspan>
|
||||
</text>
|
||||
<text id="state:-"pending"-res" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#8A704D">
|
||||
<tspan x="21" y="54.4316406">state: "pending"</tspan>
|
||||
<tspan x="21" y="74.4316406">result: undefined</tspan>
|
||||
</text>
|
||||
<path id="Line-Copy" d="M297.500387,61.4861111 L198.490385,61.4861111 L198.490385,59.4861111 L297.500387,59.4861111 L297.500387,53.4861111 L311.500387,60.4861111 L297.500387,67.4861111 L297.500387,61.4861111 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
<text id="reject(error)" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#EE6B47">
|
||||
<tspan x="201.4" y="49">reject(error)</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1-Copy-3" stroke="#C74A6C" stroke-width="2" fill="#FCDFE1" x="322" y="34" width="175" height="58"></rect>
|
||||
<text id="state:-"rejected"-re" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#727155">
|
||||
<tspan x="337" y="55.4316406">state: "rejected"</tspan>
|
||||
<tspan x="337" y="75.4316406">result: error</tspan>
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 14 KiB |
27
1-js/11-async/02-promise-basics/promise-resolve-1.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="512px" height="106px" viewBox="0 0 512 106" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>promise-resolve-1.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="promise" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="promise-resolve-1.svg">
|
||||
<path d="M9,34 L9,92 L184,92 L184,34 L9,34 Z" id="Rectangle-1" stroke="#E8C48E" stroke-width="2" fill="#FFF9EB"></path>
|
||||
<text id="new-Promise(executor" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#707175">
|
||||
<tspan x="10" y="22">new Promise(executor)</tspan>
|
||||
</text>
|
||||
<text id="state:-"pending"-res" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#8A704D">
|
||||
<tspan x="21" y="54.4316406">state: "pending"</tspan>
|
||||
<tspan x="21" y="74.4316406">result: undefined</tspan>
|
||||
</text>
|
||||
<path id="Line-Copy" d="M295.500387,61.4861111 L196.490385,61.4861111 L196.490385,59.4861111 L295.500387,59.4861111 L295.500387,53.4861111 L309.500387,60.4861111 L295.500387,67.4861111 L295.500387,61.4861111 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
<text id="resolve("done")" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#EE6B47">
|
||||
<tspan x="192" y="49">resolve("done")</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1-Copy" stroke="#7ED321" stroke-width="2" fill="#FFF9EB" x="323" y="35" width="181" height="57"></rect>
|
||||
<text id="state:-"fulfilled"-r" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#417505">
|
||||
<tspan x="338" y="55.4316406">state: "fulfilled"</tspan>
|
||||
<tspan x="338" y="75.4316406">result: "done"</tspan>
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 25 KiB |
36
1-js/11-async/02-promise-basics/promise-resolve-reject.svg
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="512px" height="246px" viewBox="0 0 512 246" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>promise-resolve-reject.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="promise" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="promise-resolve-reject.svg">
|
||||
<rect id="Rectangle-1" stroke="#E8C48E" stroke-width="2" fill="#FFF9EB" x="9" y="91" width="170" height="70"></rect>
|
||||
<text id="new-Promise(executor" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#707175">
|
||||
<tspan x="10" y="82">new Promise(executor)</tspan>
|
||||
</text>
|
||||
<text id="state:-"pending"-res" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#8A704D">
|
||||
<tspan x="21" y="115.431641">state: "pending"</tspan>
|
||||
<tspan x="21" y="135.431641">result: undefined</tspan>
|
||||
</text>
|
||||
<path id="Line" d="M299.865748,184.482759 L195.673354,136.489909 L196.510091,134.673354 L300.702485,182.666204 L303.212697,177.21654 L313,189.431641 L297.355537,189.932423 L299.865748,184.482759 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
<path id="Line-Copy" d="M300.492513,63.3688916 L196.467935,107.310308 L195.689692,105.467935 L299.71427,61.5265189 L297.379539,55.9994011 L313,57 L302.827244,68.8960094 L300.492513,63.3688916 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
<text id="resolve(value)" transform="translate(244.389895, 72.629682) rotate(-23.000000) translate(-244.389895, -72.629682) " font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#EE6B47">
|
||||
<tspan x="185.589895" y="77.1296818">resolve(value)</tspan>
|
||||
</text>
|
||||
<text id="reject(error)" transform="translate(251.633927, 150.640538) rotate(25.000000) translate(-251.633927, -150.640538) " font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" fill="#EE6B47">
|
||||
<tspan x="197.033927" y="155.140538">reject(error)</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1-Copy" stroke="#7ED321" stroke-width="2" fill="#FFF9EB" x="323" y="10" width="182" height="64"></rect>
|
||||
<text id="state:-"fulfilled"-r" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#417505">
|
||||
<tspan x="338" y="34.4316406">state: "fulfilled"</tspan>
|
||||
<tspan x="338" y="54.4316406">result: value</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1-Copy-3" stroke="#C74A6C" stroke-width="2" fill="#FCDFE1" x="323" y="177" width="182" height="64"></rect>
|
||||
<text id="state:-"rejected"-re" font-family="PTMono-Regular, PT Mono" font-size="14" font-weight="normal" line-spacing="20" fill="#727155">
|
||||
<tspan x="338" y="201.431641">state: "rejected"</tspan>
|
||||
<tspan x="338" y="221.431641">result: error</tspan>
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 59 KiB |