Multi-threaded JavaScript¶
Web Assembly (WASM)¶
- example: Figma
- the menus are in React
- the main body is in Rust
Web workers¶
Web worker vs main thread
- no access to DOM
- can still
fetch()
,setTimeout()
Service workers¶
Web workers vs service workers¶
Generators¶
same as Python!
function* fibonacci() {
let [prev, curr] = [0, 1];
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
for (n of fibonacci()) {
if (n > 100) break;
console.log(n);
}
Generators before async/await¶
How async/await
is implemented behind the scenes
Before async/await, you needed a library
var mongo = prom.promisifyAll(require("mongodb"));
var MongoClient = mongo.MongoClient;
var connectToMongo = prom.coroutine(function* () {
var db = yield MongoClient.connect(mongoURL);
return db;
});
var doMongo = prom.coroutine(function* () {
var db = yield connectToMongo("mongodb://localhost:27017");
});
Last update:
2023-04-24