diff --git a/content/notes/06-async-javascript.md b/content/notes/06-async-javascript.md new file mode 100644 index 000000000..c5d3c0cb3 --- /dev/null +++ b/content/notes/06-async-javascript.md @@ -0,0 +1,33 @@ +--- +title: "06-async-javascript" +aliases: +tags: +- lecture +- cosc203 +--- + +Async programming allows you to start a potentially long running task have still be able to interact while it it running + +general process +- start the task +- return immediately so other tasks can run +- notify us with result when the task is finished + + +promises +- an object returned by an async function +- represents the current state of the operation +- when the promise is returned to the caller it not always finished +- the promise object has methods to handle the eventual success or failure of the operation + +``` +const fetchPromise = fetch('https://url.url.json') + +fetchPromise + .then((reponse) => { + return response.json(); + }) + .then((data) => { + console.log(data[0].name) + }) +``` diff --git a/content/notes/cosc-203.md b/content/notes/cosc-203.md index 741dfdfff..98b7fe25c 100644 --- a/content/notes/cosc-203.md +++ b/content/notes/cosc-203.md @@ -36,6 +36,7 @@ tags: - [02-basic-css](notes/02-basic-css.md) - [03-more-css](notes/03-more-css.md) - [05-javascript](notes/05-javascript.md) +- # Archive