Skip to content

IrinaSing/asynchronous-programming

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

175 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asynchronous Programming

"Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things at a time and you don't have to finish executing the current thing in order to move on to next one."


"The Internet", "The Web", "Web Apps". All of these terms describe something that is interconnected. If you zoom out a bit, the entire internet is basically billions of computers all sharing information and software! But so far your projects have been all alone on your computer :(

Everything you have learned so far happens on the callstack, everything on the callstack executes synchronously. Synchronous means that each line of code will finish executing before the next one starts. Think of infinite loops, your browser freezes because nothing else can happen while the loop is looping!

What makes web development so cool is the ... web. Being able to build applications that connect computers form across the internet. This also introduces some challenges, it can take some time for computers to talk to each other across the internet. You don't want your apps freezing while you wait to hear back from another computer.

Enter asynchronous programming: writing code that tells your browser to start one task and move on to a new task while you wait for the first to finish. This is possible because of the Event Loop.

Contents

Getting Started

How to study the code in this repo.

You will need NPM and nvm on your computer to study this material

Using a browser with good DevTools will make your life easier: Chromium, FireFox, Edge, Chrome

  1. Install or update the study-lenses package globally
    • npm install -g study-lenses (if you do not have it already)
    • npm update -g study-lenses (if you already have it installed)
  2. Clone this repository:
    • git clone git@github.com:HackYourFutureBelgium/asynchronous-programming.git (SSH) (recommended)
    • git clone https://github.com/HackYourFutureBelgium/asynchronous-programming.git (HTTPS)
    • gh repo clone HackYourFutureBelgium/asynchronous-programming (GH CLI)
  3. cd into the repository
    • cd asynchronous-programming
  4. Run the study command from your CLI
    • study
  5. The material will open in your default browser, you're good to go!

If you have a windows computer and get this error:

  • ... /study.ps1 cannot be loaded because running scripts ...

follow the instructions in this StackOverflow answer, that should take care of it ; )

TOP


Learning Objectives

  • Browser
    • Using setTimeout and setInterval to schedule tasks on the Event Loop
    • Using Promise to write more manageable asynchronous code
    • Refactoring promises to async/await
    • Using fetch to get and consume data from APIs

TOP


About the Projects

Projects in this module will build on what you learned in the last module by adding in network calls to APIS and scheduled tasks on the event loop.

TOP


Suggested Study

References and Practice to help you master this module.

expand/collapse

The Event Loop

Callbacks, Promises, Async

APIs

fetch


TOP


Week 1

The Event Loop!

expand/collapse

Before Class

During Class

Before Break

After break

After Class

individual project

Try to reverse-engineer stopwatch.net 3 times:

  1. using setTimeout, setInterval, clearTimeout and clearInterval
  2. using Promises
  3. using async and await

There is not starter repository and you do not need to write a full Single Page App, one JS script for each version is ok. You should focus on the event loop and the user experience.

- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
  - with one page for each version
  - each version can be identical for the user, but have different code
- [/planning](https://github.com/_/_/tree/master/planning)
  - [ ] constraints
  - [ ] backlog
  - [ ] wireframe
  - [ ] development strategy
  - [ ] retrospective

TOP


Week 2

async/await, Fetching Data and RESTful APIs

expand/collapse

Before Class

During Class

Before Break

  • What is async/await? Cover some examples together.
  • APIs - https://jsonplaceholder.typicode.com/users/1
    • put this URL into the browser URL bar, what happens?
    • now try fetch("https://jsonplaceholder.typicode.com/users/1") in your console, what do you see?
    • how can you get the data from the response?
  • API Call functions
    • examples

After Break

  • API Call functions
    • exercises

After Class

individual project

You've made it this far, time to show off a bit! Build yourself a new home page + portfolio to show off what you've built. You will use the GitHub API to fetch data about your profile, your projects, your contributions, whatever you're most proud of. (hint: avoid pushing your GitHub auth token!). Here's some links to get you started:

And a checklist:

- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
- [/planning](https://github.com/_/_/tree/master/planning)
  - [ ] constraints
  - [ ] backlog
  - [ ] wireframe
  - [ ] development strategy
  - [ ] retrospective
- [ ] [project board](https://github.com/_/_/projects/1)

TOP


Week 3

Project week, no new material!

expand/collapse

Before Class

Take it easy, focus on your portfolio

During Class

  • Questions and answers + code review
  • All together then in small groups

After Class

Keep working on your home page. No worries if you don't finish it this week! It's always a work in progress, and you'll have much more to add after next module.


TOP


Class Recordings

  • Students: Here you can find recordings of this module from past classes. Enjoy!
  • Coaches: When sending your PR's with links please ...
    • Indicate which class you were teaching
    • Which week it was (if the module is more than 1 week)
    • Give your name
    • and a helpful description

Class 7 & 8

Anthony, Kevin

  1. week 1:
  2. week 2:
  3. week 3:

Bram, Deni

  1. week 1:
  2. week 2:
  3. week 3:

Bram, Thibault

  1. week 1: Scheduling & The Event Loop. setTimeout, setInterval
  2. week 2: Promises & fetch
  3. week 3: async/await & fetch
  1. week 1 - by Yoshi and Joel:

About

Event Loop, callbacks, promises, API's, file system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 93.7%
  • JavaScript 6.3%