1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
-
- <script>
- function myfetch(url){
- return new Promise(function (resolve, reject){
- console.log('panding')
- const xhr = new XMLHttpRequest()
- xhr.open('GET', url);
- xhr.send();
- xhr.onload = function() {
- if (xhr.status != 200) {
- reject("xhr.status != 200")
- return
- }
- resolve(JSON.parse(xhr.response));
- }
- xhr.onerror = function() {
- reject("Error");
- }
- })
- }
-
- let delay2 = function (time) {
- return new Promise(function (resolve, reject) {
- console.log("delay starsing")
- setTimeout(() => resolve("Delay was first"), time);
- });
- }
-
- Promise.race([delay2(95), myfetch("https://swapi.dev/api/people/1/")]).then(res => console.log(res));
- </script>
- </body>
- </html>
|