File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
simple-promise-def/the-event-loop Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "singleQuote": true,
3+ "arrowParens": "avoid"
4+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge " />
7+ < title > Understanding Async JavaScript Behind the Scenes</ title >
8+ < style >
9+ body {
10+ height : 100vh ;
11+ display : flex;
12+ align-items : center;
13+ background : linear-gradient (to top left, # 28b487, # 7dd56f );
14+ }
15+ h1 {
16+ font-family : sans-serif;
17+ font-size : 50px ;
18+ line-height : 1.3 ;
19+ width : 100% ;
20+ padding : 30px ;
21+ text-align : center;
22+ color : white;
23+ }
24+ </ style >
25+ < script defer src ="script.js "> </ script >
26+ </ head >
27+ < body >
28+ < h1 > Understanding Async JavaScript Behind the Scenes</ h1 >
29+ </ body >
30+ </ html >
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ //Biulding a new Promise
4+ const lotteryReq = new Promise ( function ( resolve , reject ) {
5+ console . log ( 'Checking The Results......' ) ;
6+ setTimeout ( ( ) => {
7+ if ( Math . random ( ) < 0.5 ) {
8+ resolve ( 'You WIN 💰' ) ;
9+ } else {
10+ reject ( new Error ( 'You LOST Please Try Again 😢' ) ) ;
11+ }
12+ } , 2000 )
13+
14+ } ) ;
15+
16+ lotteryReq . then ( res => console . log ( res ) ) . catch ( err => console . error ( err ) ) ;
You can’t perform that action at this time.
0 commit comments