Skip to content

Commit

Permalink
Merge pull request #25 from neu-se/module06-async
Browse files Browse the repository at this point in the history
module06 - async
  • Loading branch information
mwand authored Jan 22, 2024
2 parents cfd265f + 5670695 commit c211a66
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 1 deletion.
76 changes: 76 additions & 0 deletions Activities/Module06 Activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
layout: page
title: Async Activity
nav_exclude: true
---

# Simple Activity using async/await

Learning Objectives for this activity:
* Practice applying asynchronous programming concepts: promises, async/await
* Experiment with applying different ordering constraints in asynchronous code

## Overview
In this activity, you will experiment with asynchronous programming constructs in TypeScript.

### Getting started
Download [starter Code]({{ site.baseurl }}{% link Activities/module06-async_activity.zip %})
Run `npm install` to download the dependencies for this project, and then open it in your IDE of choice.
Run `npm run client` to run the client as-is, the output should be something like:

```
Creating a student
Import grades completed, and returned:
[
{
"student": {
"studentID": 17,
"studentName": "test student"
},
"grades": [
{
"course": "demo course",
"grade": 100
}
]
}
]
```

### Stringing together many async calls: bulk importing grades
Your task is to write a new, `async` function, `importGrades`, which takes in input of the type `ImportTranscript[]`.
`importGrades` should create a student record for each `ImportTranscript`, and then post the grades for each of those students.
After posting the grades, it should fetch the transcripts for each student and return an array of transcripts.

You should implement `importGrades` in the file `examples.ts` - note that there is already a function stub there.
As you get started, examine the transcript server client in `client.ts`, and take note of the API calls that are available to you.

Here is the type definition for `ImportTranscript` and its dependencies:
```
type ImportTranscript = {
studentName: string;
grades: CourseGrade[];
};
type CourseGrade = { course: Course, grade: number };
type Course = string;
```

Example input:
```
[
{
studentName: "Avery",
grades: [{course: "Software Engineering", grade: 100}, {course: "Chemistry", grade: 70}],
},
{
studentName: "Ripley",
grades: [{course: "Underwater Basket Weaving", grade: 100}, {course: "Kayaking", grade: 90} ]
}
]
```

Implement this three ways:
1. Insert a student, insert each of their grades (in order), then insert the next student, then their grades, etc. until all students are inserted, then fetch transcripts
2. Insert a student, then insert each of their grades (in order), then fetch their transcript. Do this set of operations asynchronously (concurrently) for all students
3. Insert a student, then insert each of their grades asynchronously (concurrently). After all students have all of their grades submitted, fetch all fo the transcripts asynchronously (concurrently)
Binary file added Activities/module06-async_activity.zip
Binary file not shown.
Binary file added Examples/module-06-async-examples.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions _announcements/week-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Team Formation Survey is Now Available
week: 4
date: 2024-01-23
---
Please complete this [Team Formation Survey](https://northeastern.instructure.com/courses/166618/assignments/2184900) to help us organize you into a team for the term project. EVERY STUDENT must fill this form out by 11am on Wednesday 1/31/2024, or risk being placed in a random team.

{: .fs-5 }
2 changes: 1 addition & 1 deletion _data/modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
page: /modules/5-interaction-level-design-patterns
3b:
name: Concurrency Patterns
page:
page: /modules/6-concurrency-patterns-in-typescript
4a:
name: Software Processes & Agile
page:
Expand Down
31 changes: 31 additions & 0 deletions lectures/l6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
layout: module
title: "6 - Concurrency Patterns in Typescript"
permalink: /modules/6-concurrency-patterns-in-typescript
parent: Modules
nav_order: 6
lessons:
- title: "Concurrency Patterns in Typescript"
ppt: "Module 06 Concurrency Patterns in Typescript.pptx"
pdf: "Module 06 Concurrency Patterns in Typescript.pdf"

---
### Learning Objectives:
A 1 GHz CPU executes an instruction every 1 ns. Almost anything else takes approximately forever. Rather than waste time waiting for a long-running operation to complete, we want our programs to make progress on other tasks. This is called "masking latency with concurrency".

In this lecture, we will study some common patterns for organizing concurrency in Typescript/Javascript.

By the end of this lesson, you should be prepared to:
* Explain the difference between JS run-to-completion semantics and interrupt-based semantics.
* Given a simple program using async/await, work out the order in which the statements in the program will run.
* Write simple programs that create and manage promises using async/await
* Write simple programs to mask latency with concurrency by using non-blocking IO and Promise.all in TypeScript.


{% include lesson.html %}

### Activities:
* [Async Activity]({{ site.baseurl }}{% link Activities/Module06 Activity.md %})

### Resources
* [Code Examples from Slides]({{ site.baseurl }}{% link Examples/module-06-async-examples.zip %})

0 comments on commit c211a66

Please sign in to comment.