mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 21:34:06 -06:00
vault backup: 2022-07-29 11:00:53
This commit is contained in:
parent
56eef6b945
commit
8800ef8ad9
33
content/notes/06-async-javascript.md
Normal file
33
content/notes/06-async-javascript.md
Normal file
@ -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)
|
||||
})
|
||||
```
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user