Created
June 14, 2017 22:19
-
-
Save featheredtoast/3e34321092536d919221897e4383cc96 to your computer and use it in GitHub Desktop.
quick test for async/await syntax in es7 vs pure promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script> | |
| var args = { | |
| headers: new Headers({ | |
| 'Content-Type': 'text/plain' | |
| })}; | |
| async function useAwaits() { | |
| try { | |
| let resp = await fetch("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&origin=*&search=stack&limit=10", args); | |
| let t = await resp.json(); | |
| return t; | |
| } catch(e) { | |
| return e.message; | |
| } | |
| } | |
| function promisesOnly() { | |
| return fetch("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&origin=*&search=stack&limit=10", args).then( | |
| (res) => {return res.json();}, | |
| (res) => {return res.message}); | |
| } | |
| useAwaits().then((res) => {console.log("awaits: " + JSON.stringify(res));}); | |
| promisesOnly().then((res) => {console.log("pure promises: " + JSON.stringify(res));}); | |
| </script> | |
| <body> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment