SlideShare ist ein Scribd-Unternehmen logo
1 von 175
Downloaden Sie, um offline zu lesen
Asynchronicity: concurrency. A tale of
(a.k.a: the subtle art of making a PB&J sandwich)
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
@joel__lord
#iJS18
PHP Javascript
<script type="text/javascript">
console.log("Before reading file");
getFileContent("sample.txt", () => {
console.log("After file read");
});
console.log("Before HTTP request");
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (this.readyState === XMLHttpRequest.DONE
&& this.status === 200) {
console.log("After HTTP request");
}
};
req.open("GET", "https://swapi.co/api/planets/1");
req.send(null);
</script>
<?php
echo("Before reading filen");
$fileContents =
file_get_contents("sample.txt");
echo("After file readn");
echo("Before HTTP requestn");
$ch = curl_init("https://swapi.co/api/
planets/1/");
$data = curl_exec($ch);
curl_close($ch);
echo("After HTTP requestn");
TitleRace Conditions
@joel__lord
#iJS18
About Me
@joel__lord
joellord
@joel__lord
#iJS18
WARNING
@joel__lord
#iJS18
WARNING
175 slides
@joel__lord
#iJS18
Our Agenda
! Event Loop
! Callbacks
! Promises
! Generators
! Await/Async
! Events
! Reactive Events
How to make a PB&J sandwich
@joel__lord
#iJS18
PB&J Sandwich
ā€¢ Get the ingredients
ā€£ Get some bread
ā€£ Get some PB
ā€£ Get some J
ā€¢ Prepare the sandwich
ā€£ Spread PB
ā€£ Spread J
ā€¢ Close it
ā€¢ Eat it!
The Event Loop
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
!
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢
!
šŸ„Ŗ
šŸž
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
!
šŸ„Ŗ
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
!
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
!
šŸ„Ŗ
šŸž
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
!
šŸ„Ŗ
šŸž
šŸ„œ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
!
šŸ„Ŗ
šŸž
šŸ„œ
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Classic Architecture
(PHP, Java)
ā€¢ I want a sandwich!
ā€¢ Process start
ā€¢ Fetches the
ingredients
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Another process starts
ā€¢ Fetches the
ingredients
ā€¢ Prepares the
sandwich
ā€¢ Hereā€™s your
sandwich !
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
!
šŸ„Ŗ
šŸ“
šŸž
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
!
šŸ„Ŗ
šŸ“
šŸž
šŸ„œ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
!
šŸ„Ŗ
šŸ“
šŸž
šŸ„œ
šŸ„Ŗ
šŸ“
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
!
šŸ„Ŗ
šŸ“
šŸž
šŸ„œ
šŸ„Ŗ
šŸ“
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„œ
!
šŸ„Ŗ
šŸ“
šŸž
šŸ„œ
šŸ„Ŗ
šŸ“
šŸ„Ŗ
šŸ„Ŗ
@joel__lord
#iJS18
Event Loop
(NodeJS)
ā€¢ I want a sandwich!
ā€¢ Sure
ā€¢ ā€œWorker, Make a
sandwichā€
ā€¢ A new customer arrives:
I want a sandwich!
ā€¢ Sure
ā€¢ ā€œOther worker,
make a sandwichā€
ā€¢ Here is your sandwich
customer 1
!
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
šŸž
šŸ„œ
šŸ“
šŸ„Ŗ
!
šŸ„Ŗ
!
šŸ„Ŗ
šŸ„Ŗ
šŸ„Ŗ
šŸ„Ŗ
Synchronous JS
(2000ā€™s)
@joel__lord
#iJS18
Code
let PBnJMaker = require("./pbnjmaker");
PBnJMaker.fetchBread();
PBnJMaker.fetchPeanutButter();
PBnJMaker.fetchJam();
PBnJMaker.spreadPeanutButter();
PBnJMaker.spreadJam();
let result = PBnJMaker.closeSandwich();
console.log("Eat that " + result);
@joel__lord
#iJS18
Result
Callbacks
(2010ā€™s)
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
// //Synchronous
let array = [1,2,3];
console.log("begin");
array.map((i) => {console.log(i)});
console.log("after");
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
//Asynchronous
console.log("begin");
fs.readFile("./cb.txt", (err, data) => {
console.log(ā€œFile contentā€);
});
console.log("after");
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
//Asynchronous
console.log("begin");
fs.readFile("./cb.txt", (err, data) => {
console.log(ā€œFile contentā€);
});
console.log("after");
@joel__lord
#iJS18
What is a callback
! Simply a function as
an argument to a
function
! Could be
synchronous or
asynchronous
//Asynchronous
.....................
....................... (err, data) => {
console.log(ā€œFile contentā€);
}..
.....................
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
console.log("begin");
fs.readFile("./cb.txt",
(err, data) => {
console.log(data);
});
console.log("after");
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
fs.readFile("./cb.txt",
(err, data) => {
console.log(data);
});
console.log("after");
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
console.log("after"); (err, data) => {
console.log(data);
}
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
(err, data) => {
console.log(data);
}
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
(err, data) => {
console.log(data);
}
@joel__lord
#iJS18
What is a callback
Asynchronous callback and the event loop
@joel__lord
#iJS18
Code
let PBnJMaker = require("../pbnjmaker");
PBnJMaker.fetchBread(() => {
PBnJMaker.fetchPeanutButter(() => {
PBnJMaker.fetchJam(() => {
PBnJMaker.spreadPeanutButter(() => {
PBnJMaker.spreadJam(() => {
PBnJMaker.closeSandwich((err, output) => {
console.log("Eat that " + output);
});
});
});
});
});
});
@joel__lord
#iJS18
Result
@joel__lord
#iJS18
Callbacks
! It works!
! butā€¦
let PBnJMaker = require("../pbnjmaker");
PBnJMaker.simulateError();
PBnJMaker.fetchBread((err) => {
if (err) {
console.log("An error occurred while fetching the ingredients");
} else {
PBnJMaker.fetchPeanutButter((err) => {
if (err) {
console.log("An error occurred while fetching the ingredients");
} else {
PBnJMaker.fetchJam((err) => {
if (err) {
console.log("An error occurred while fetching the ingredients");
} else {
PBnJMaker.spreadPeanutButter((err) => {
if (err) {
console.log("An error occurred whileā€¦ the sandwich");
} else {
PBnJMaker.spreadJam((err) => {
if (err) {
console.log("An error occurred ā€¦ the sandwich");
} else {
PBnJMaker.closeSandwich((err, result) => {
if (err) {
console.log("An error occurred");
} else {
console.log("Eat that " + result);
}
});
}
});
}
});
}
});
}
});
}
});
@joel__lord
#iJS18
Callback Hell
let PBnJMaker = require("../pbnjmaker");
PBnJMaker.simulateError();
PBnJMaker.fetchBread((err) => {
if (err) {
console.log("An error occurred while fetching the ingredients");
} else {
PBnJMaker.fetchPeanutButter((err) => {
if (err) {
console.log("An error occurred whileā€¦ ingredients");
} else {
PBnJMaker.fetchJam((err) => {
Parallel events
@joel__lord
#iJS18
Step by step Parallel events
šŸ“šŸž
šŸ„œ
šŸ„Ŗ
šŸž
šŸ„œ
šŸ„Ŗ
šŸ“
@joel__lord
#iJS18
Code
let PBnJMaker = require("../pbnjmaker");
@joel__lord
#iJS18
Code
let ingredients = 0;
let steps = 0;
@joel__lord
#iJS18
Code
function fetchIngredients() {
}
@joel__lord
#iJS18
Code
function fetchIngredients() {
PBnJMaker.fetchBread(handleIngredients);
PBnJMaker.fetchPeanutButter(handleIngredients);
PBnJMaker.fetchJam(handleIngredients);
}
@joel__lord
#iJS18
Code
function handleIngredients(err) {
if (err) return console.log(ā€œErrorā€);
ingredients++;
if (ingredients === 3) {
prepareSandwich();
}
}
@joel__lord
#iJS18
Code
function prepareSandwich() {
PBnJMaker.spreadPeanutButter(preparationStepCompleted);
PBnJMaker.spreadJam(preparationStepCompleted);
}
@joel__lord
#iJS18
Code
function preparationStepCompleted(err) {
if (err) return console.log(ā€œError");
steps++;
if (steps === 2) {
completeSandwich();
}
}
@joel__lord
#iJS18
Code
function completeSandwich(err) {
PBnJMaker.closeSandwich((err, result) => {
if (err) {
console.log("An error occurred");
} else {
console.log("Eat that " + result);
}
});
}
@joel__lord
#iJS18
Code
fetchIngredients();
@joel__lord
#iJS18
Result
Parallel
Promises
(2014)
@joel__lord
#iJS18
What is a promise?
! A representation of a
callback
! Returns a .then()
method
! Error handling
simplified
//Asynchronous
console.log("begin");
asyncPromise().then(onSuccess, onFailure);
console.log("after");
@joel__lord
#iJS18
What is a promise?
! A representation of a
callback
! Returns a .then()
method
! Error handling
simplified
//Asynchronous
console.log("begin");
fs.readFile("./cb.txt")
.then((data) => {
console.log(data);
}, (err) => {
console.log(err);
});
console.log("after");
@joel__lord
#iJS18
What is a promise?
! A representation of a
callback
! Returns a .then()
method
! Error handling
simplified
//Asynchronous
console.log("begin");
fs.readFile("./cb.txt")
.then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});
console.log("after");
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread()
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread().then(() => {
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread().then(() => {
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread().then(() => {
return PBnJMaker.fetchPeanutButter();
})
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread().then(() => {
return PBnJMaker.fetchPeanutButter();
}).then(() => {
@joel__lord
#iJS18
Code Result
PBnJMaker.fetchBread().then(() => {
return PBnJMaker.fetchPeanutButter();
}).then(() => {
return PBnJMaker.fetchJam();
@joel__lord
#iJS18
Code Result
}).then(() => {
return PBnJMaker.spreadPeanutButter();
@joel__lord
#iJS18
Code Result
}).then(() => {
return PBnJMaker.spreadJam();
@joel__lord
#iJS18
Code Result
}).then(() => {
return PBnJMaker.closeSandwich();
@joel__lord
#iJS18
Code Result
}).then((result) => {
console.log("Eat that " + result);
@joel__lord
#iJS18
Code Result
@joel__lord
#iJS18
Code Result
}).catch((err) => {
console.log("Error with ingredients");
@joel__lord
#iJS18
Code Result
}).catch((err) => {
console.log("Error with ingredients");
}).catch((err) => {
console.log(ā€œError preparingā€);
}).catch((err) => {
console.log(ā€œError somewhereā€);
@joel__lord
#iJS18
Result
Promises
@joel__lord
#iJS18
Aggregate functions
! .all()
! .race()
let PBnJMaker = require("../pbnjmaker");
Promise.all([
PBnJMaker.fetchBread(),
PBnJMaker.fetchPeanutButter(),
PBnJMaker.fetchJam()])
.then(() => {
return Promise.all([
PBnJMaker.spreadPeanutButter(),
PBnJMaker.spreadJam()]);
}).then(() => {
return PBnJMaker.closeSandwich();
}).then((result) => {
console.log("Eat that " + result);
});
@joel__lord
#iJS18
Aggregate functions
! .all()
! .race()
let PBnJMaker = require("../pbnjmaker");
Promise.all([
PBnJMaker.fetchBread(),
PBnJMaker.fetchPeanutButter(),
PBnJMaker.fetchJam()])
.then(() => {
return Promise.all([
PBnJMaker.spreadPeanutButter(),
PBnJMaker.spreadJam()]);
}).then(() => {
return PBnJMaker.closeSandwich();
}).then((result) => {
console.log("Eat that " + result);
});
@joel__lord
#iJS18
Aggregate functions
! .all()
! .race()
let PBnJMaker = require("../pbnjmaker");
Promise.all([
PBnJMaker.fetchBread(),
PBnJMaker.fetchPeanutButter(),
PBnJMaker.fetchJam()])
.then(() => {
return Promise.all([
PBnJMaker.spreadPeanutButter(),
PBnJMaker.spreadJam()]);
}).then(() => {
return PBnJMaker.closeSandwich();
}).then((result) => {
console.log("Eat that " + result);
});
@joel__lord
#iJS18
Aggregate functions
! .all()
! .race()
let PBnJMaker = require("../pbnjmaker");
Promise.all([
PBnJMaker.fetchBread(),
PBnJMaker.fetchPeanutButter(),
PBnJMaker.fetchJam()])
.then(() => {
return Promise.all([
PBnJMaker.spreadPeanutButter(),
PBnJMaker.spreadJam()]);
}).then(() => {
return PBnJMaker.closeSandwich();
}).then((result) => {
console.log("Eat that " + result);
});
Generators
(2015)
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
let iteration = iterable();
console.log(iteration.next()); // 3
// Do stuff
console.log(iteration.next()); // 2
console.log(iteration.next()); // 1
console.log(iteration.next()); // 0
// More stuff
console.log(iteration.next()); // undefined
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
for (let iteration of iterable()) {
console.log(iteration);
}
// 3
// 2
// 1
// 0
@joel__lord
#iJS18
What is a generator?
! An iterable function
! ā€œPausesā€ the
execution of a
function
function* iterable() {
let i = 4;
while(i--) {
yield i;
}
}
for (let iteration of iterable()) {
console.log(iteration);
}
// 3
// 2
// 1
// 0
@joel__lord
#iJS18
Code Result
let PBnJMaker = require("../pbnjmaker");
PBnJMaker.verbose();
function* makePBnJ() {
yield PBnJMaker.fetchBread;
yield PBnJMaker.fetchPeanutButter;
yield PBnJMaker.fetchJam;
yield PBnJMaker.spreadPeanutButter;
yield PBnJMaker.spreadJam;
yield PBnJMaker.closeSandwich;
}
for (let step of makePBnJ()) {
step();
}
console.log("Eat that sandwich");
@joel__lord
#iJS18
Async Generators
! Combining the power
of promises and
generators
module.exports = (makeGenerator) => {
let generator = makeGenerator.apply(this, arguments);
function handle(result) {
// generator returns {done: [Boolean], value: [Any}}
if (result.done)
return Promise.resolve(result.value);
return
Promise.resolve(result.value).then(function(res) {
return handle(generator.next(res));
}, function(err) {
return handle(generator.throw(err));
});
}
try {
return handle(generator.next());
} catch(e) {
return Promise.reject(e);
}
};
@joel__lord
#iJS18
Code Result
let PBnJMaker = require("../pbnjmaker");
let async = require("../async");
function* makePBnJ() {
yield PBnJMaker.fetchBread();
yield PBnJMaker.fetchPeanutButter();
yield PBnJMaker.fetchJam();
yield PBnJMaker.spreadPeanutButter();
yield PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
async(makePBnJ).then((result) => {
console.log("Eat that " + result);
});
@joel__lord
#iJS18
Code Result
let PBnJMaker = require("../pbnjmaker");
let async = require("../async");
function* makePBnJ() {
yield PBnJMaker.fetchBread();
yield PBnJMaker.fetchPeanutButter();
yield PBnJMaker.fetchJam();
yield PBnJMaker.spreadPeanutButter();
yield PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
async(makePBnJ).then((result) => {
console.log("Eat that " + result);
});
Async / Await
(2017)
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Newly introduced in
ES8 (ES2017)
! Natural evolution of
generators and
promises
let PBnJMaker = require("../pbnjmaker");
async function makePBnJ() {
await PBnJMaker.fetchBread();
await PBnJMaker.fetchPeanutButter();
await PBnJMaker.fetchJam();
await PBnJMaker.spreadPeanutButter();
await PBnJMaker.spreadJam();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log(ā€œEat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
What is async/await?
! Very easy to
parallelize processes
let PBnJMaker = require("../pbnjmaker");
async function getIngredients() {
let p1 = PBnJMaker.fetchBread();
let p2 = PBnJMaker.fetchPeanutButter();
let p3 = PBnJMaker.fetchJam();
return await p1 + await p2 + await p3;
}
async function prepareSandwich() {
let p1 = PBnJMaker.spreadPeanutButter();
let p2 = PBnJMaker.spreadJam();
return await p1 + await p2;
}
async function makePBnJ() {
await getIngredients();
await prepareSandwich();
return PBnJMaker.closeSandwich();
}
makePBnJ().then((result) => {
console.log("Eat that " + result)
});
@joel__lord
#iJS18
Async / Await
Programatically define your steps
let PBnJMaker = require("../pbnjmaker");
let ingredients = ["Bread", "PeanutButter", "Jam"];
let steps = ingredients.map((i) => `fetch${i}`);
steps.push(...["spreadPeanutButter", "spreadJam"]);
async function makePBnJ(todo) {
for (var i = 0; i < todo.length; i++) {
await PBnJMaker[todo[i]]();
}
return PBnJMaker.closeSandwich();
}
makePBnJ(steps).then((result) => {
console.log(ā€œEat that " + result)
});
Events
(1990ā€™s)
@joel__lord
#iJS18
Events in the browser
! At the core of the
original Javascript
! window.onready = ā€¦
! button.onclick = ā€¦
@joel__lord
#iJS18
Node Event Emitter
! In node, you can use
the event emitter
! Create you own
events for a library
@joel__lord
#iJS18
Node Event Emitter
! In node, you can use
the event emitter
! Create you own
events for a library
@joel__lord
#iJS18
Code Demo
@joel__lord
#iJS18
Code Demo
Reactive Stream
(2017)
@joel__lord
#iJS18
RxJS
! Manipulate data,
synchronous or
asynchronous as
streams
! Manipulate streams
like arrays
@joel__lord
#iJS18
Code Demo
@joel__lord
#iJS18
RxJS
! RTFM
In Conclusion
(cā€™est presque la faim)
@joel__lord
#iJS18
Summary
Asynchronous patterns
! The Event Loop
! Callbacks
! Promises
! Generators
! Async/Await
! Events
! Reactive Stream
@joel__lord
#iJS18
Summary
Asynchronous patterns
! The Event Loop
! Callbacks
! Promises
! Generators
! Async/Await
! Events
! Reactive Stream
! ā€¦. How to make a PBnJ sandwich!
Asynchronicity: concurrency. A tale of
iJS, London, UK
April 11, 2018
@joel__lord
joellord
Special thanks to
@tomasz_ducinĀ for the inspiration

Weitere Ƥhnliche Inhalte

Was ist angesagt?

groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12Alexandre Masselot
Ā 
RESTful Web Applications with Google Go
RESTful Web Applications with Google GoRESTful Web Applications with Google Go
RESTful Web Applications with Google GoFrank MĆ¼ller
Ā 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2Alexandre Masselot
Ā 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8WindowsPhoneRocks
Ā 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsBartosz Konieczny
Ā 
Integration with Camel
Integration with CamelIntegration with Camel
Integration with CamelJosuƩ Neis
Ā 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDBartłomiej Kiełbasa
Ā 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBSqreen
Ā 
PuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppet
Ā 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot Nidhi Chauhan
Ā 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots DeepAnshu Sharma
Ā 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developersSimon Elliston Ball
Ā 
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObject
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObjectHtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObject
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObjectSQALab
Ā 
groovy & grails - lecture 11
groovy & grails - lecture 11groovy & grails - lecture 11
groovy & grails - lecture 11Alexandre Masselot
Ā 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientDimitar Ivanov
Ā 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# DevelopersSimon Elliston Ball
Ā 
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼Ryosuke Uchitate
Ā 
Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Devon Bernard
Ā 
NodeJs
NodeJsNodeJs
NodeJsdizabl
Ā 

Was ist angesagt? (20)

groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
Ā 
RESTful Web Applications with Google Go
RESTful Web Applications with Google GoRESTful Web Applications with Google Go
RESTful Web Applications with Google Go
Ā 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
Ā 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8
Ā 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasets
Ā 
Integration with Camel
Integration with CamelIntegration with Camel
Integration with Camel
Ā 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
Ā 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
Ā 
PuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbquery
Ā 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
Ā 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
Ā 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
Ā 
Dropwizard
DropwizardDropwizard
Dropwizard
Ā 
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObject
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObjectHtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObject
HtmlElements ā€“ ŠµŃŃ‚ŠµŃŃ‚Š²ŠµŠ½Š½Š¾Šµ рŠ°ŃŃˆŠøрŠµŠ½ŠøŠµ PageObject
Ā 
groovy & grails - lecture 11
groovy & grails - lecture 11groovy & grails - lecture 11
groovy & grails - lecture 11
Ā 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP Client
Ā 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
Ā 
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼
Amazon Cognitoä½æć£ć¦čŖčØ¼ć—ćŸć„ļ¼Ÿćć‚ŒćŖ悉Spring Securityä½æć„ć¾ć—ć‚‡ć†ļ¼
Ā 
Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]
Ā 
NodeJs
NodeJsNodeJs
NodeJs
Ā 

Ƅhnlich wie Asynchonicity: concurrency. A tale of

Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
Ā 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
Ā 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranRobert Nyman
Ā 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleCarsten Ziegeler
Ā 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten ZiegelerMonitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten Ziegelermfrancis
Ā 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleAdobe
Ā 
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSHTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSRobert Nyman
Ā 
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part A
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part AćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part A
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part AKazuchika Sekiya
Ā 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - AjaxWebStackAcademy
Ā 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonGeert Van Pamel
Ā 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
Ā 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fallShumpei Shiraishi
Ā 
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1Zianed Hou
Ā 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introductionStefan Pettersson
Ā 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSCosmin Mereuta
Ā 

Ƅhnlich wie Asynchonicity: concurrency. A tale of (20)

Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
Ā 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
Ā 
J query 01.07.2013
J query 01.07.2013J query 01.07.2013
J query 01.07.2013
Ā 
J query 01.07.2013.html
J query 01.07.2013.htmlJ query 01.07.2013.html
J query 01.07.2013.html
Ā 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
Ā 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
Ā 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten ZiegelerMonitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
Ā 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
Ā 
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSHTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
Ā 
Ajax chap 4
Ajax chap 4Ajax chap 4
Ajax chap 4
Ā 
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part A
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part AćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part A
ćŠé”Œć§Groovyćƒ—ćƒ­ć‚°ćƒ©ćƒŸćƒ³ć‚°: Part A
Ā 
Xml http request
Xml http requestXml http request
Xml http request
Ā 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
Ā 
Frontend Servers and NGINX: What, Where and How
Frontend Servers and NGINX: What, Where and HowFrontend Servers and NGINX: What, Where and How
Frontend Servers and NGINX: What, Where and How
Ā 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
Ā 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Ā 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
Ā 
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1
TomcatčæžęŽ„ę± é…ē½®ę–¹ę³•V2.1
Ā 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
Ā 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Ā 

Mehr von Joel Lord

From Ceasar Cipher To Quantum Cryptography
From Ceasar Cipher To Quantum CryptographyFrom Ceasar Cipher To Quantum Cryptography
From Ceasar Cipher To Quantum CryptographyJoel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
Mot de passe oubliƩ? Absolument!
Mot de passe oubliƩ? Absolument!Mot de passe oubliƩ? Absolument!
Mot de passe oubliƩ? Absolument!Joel Lord
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine LearningJoel Lord
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Joel Lord
Ā 
WTH is a JWT
WTH is a JWTWTH is a JWT
WTH is a JWTJoel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
WTH is a JWT
WTH is a JWTWTH is a JWT
WTH is a JWTJoel Lord
Ā 
I Don't Care About Security
I Don't Care About Security I Don't Care About Security
I Don't Care About Security Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
Ā 
Secure your SPA with Auth0
Secure your SPA with Auth0Secure your SPA with Auth0
Secure your SPA with Auth0Joel Lord
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine LearningJoel Lord
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine LearningJoel Lord
Ā 

Mehr von Joel Lord (20)

From Ceasar Cipher To Quantum Cryptography
From Ceasar Cipher To Quantum CryptographyFrom Ceasar Cipher To Quantum Cryptography
From Ceasar Cipher To Quantum Cryptography
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
Mot de passe oubliƩ? Absolument!
Mot de passe oubliƩ? Absolument!Mot de passe oubliƩ? Absolument!
Mot de passe oubliƩ? Absolument!
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine Learning
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!
Ā 
WTH is a JWT
WTH is a JWTWTH is a JWT
WTH is a JWT
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
Forgot Password? Yes I Did!
Forgot Password? Yes I Did!Forgot Password? Yes I Did!
Forgot Password? Yes I Did!
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
WTH is a JWT
WTH is a JWTWTH is a JWT
WTH is a JWT
Ā 
I Don't Care About Security
I Don't Care About Security I Don't Care About Security
I Don't Care About Security
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
Ā 
Secure your SPA with Auth0
Secure your SPA with Auth0Secure your SPA with Auth0
Secure your SPA with Auth0
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine Learning
Ā 
Learning Machine Learning
Learning Machine LearningLearning Machine Learning
Learning Machine Learning
Ā 

KĆ¼rzlich hochgeladen

Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptx
Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptxUnidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptx
Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptxmibuzondetrabajo
Ā 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
Ā 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
Ā 
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书zdzoqco
Ā 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
Ā 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
Ā 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
Ā 
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čÆä¹¦ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书rnrncn29
Ā 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
Ā 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
Ā 
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čÆä¹¦ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书rnrncn29
Ā 

KĆ¼rzlich hochgeladen (11)

Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptx
Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptxUnidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptx
Unidad 4 ā€“ Redes de ordenadores (en inglĆ©s).pptx
Ā 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
Ā 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
Ā 
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书
办ē†å¤šä¼¦å¤šå¤§å­¦ęƕäøščÆęˆē»©å•|č“­ä¹°åŠ ę‹æ大UTSGę–‡å‡­čƁ书
Ā 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
Ā 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
Ā 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
Ā 
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čÆä¹¦ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°ę‹‰ē­¹ä¼Æ大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²LTUę–‡å‡­å­¦ä½čƁ书
Ā 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
Ā 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
Ā 
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čÆä¹¦ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书
ć€Žę¾³ę“²ę–‡å‡­ć€ä¹°č©¹å§†å£«åŗ“克大学ęƕäøščÆä¹¦ęˆē»©å•åŠžē†ę¾³ę“²JCUę–‡å‡­å­¦ä½čƁ书
Ā 

Asynchonicity: concurrency. A tale of

  • 1. Asynchronicity: concurrency. A tale of (a.k.a: the subtle art of making a PB&J sandwich)
  • 2. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 3. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 4. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 5. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 6. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 7. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 8. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 9. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 10. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 11. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 12. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 13. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 14. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 15. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 16. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 17. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 18. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 19. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 20. @joel__lord #iJS18 PHP Javascript <script type="text/javascript"> console.log("Before reading file"); getFileContent("sample.txt", () => { console.log("After file read"); }); console.log("Before HTTP request"); const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { console.log("After HTTP request"); } }; req.open("GET", "https://swapi.co/api/planets/1"); req.send(null); </script> <?php echo("Before reading filen"); $fileContents = file_get_contents("sample.txt"); echo("After file readn"); echo("Before HTTP requestn"); $ch = curl_init("https://swapi.co/api/ planets/1/"); $data = curl_exec($ch); curl_close($ch); echo("After HTTP requestn");
  • 25. @joel__lord #iJS18 Our Agenda ! Event Loop ! Callbacks ! Promises ! Generators ! Await/Async ! Events ! Reactive Events
  • 26. How to make a PB&J sandwich
  • 27. @joel__lord #iJS18 PB&J Sandwich ā€¢ Get the ingredients ā€£ Get some bread ā€£ Get some PB ā€£ Get some J ā€¢ Prepare the sandwich ā€£ Spread PB ā€£ Spread J ā€¢ Close it ā€¢ Eat it!
  • 30. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ ! šŸ„Ŗ
  • 31. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ ! šŸ„Ŗ
  • 32. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ ! šŸ„Ŗ šŸž
  • 33. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ ! šŸ„Ŗ šŸž šŸ„œ
  • 34. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 35. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 36. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ
  • 37. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ
  • 38. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ
  • 39. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž
  • 40. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ ! šŸ„Ŗ
  • 41. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ ! šŸ„Ŗ ! šŸ„Ŗ
  • 42. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ ! šŸ„Ŗ šŸž ! šŸ„Ŗ
  • 43. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ ! šŸ„Ŗ šŸž
  • 44. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ ! šŸ„Ŗ šŸž šŸ„œ
  • 45. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ ! šŸ„Ŗ šŸž šŸ„œ
  • 46. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 47. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 48. @joel__lord #iJS18 Classic Architecture (PHP, Java) ā€¢ I want a sandwich! ā€¢ Process start ā€¢ Fetches the ingredients ā€¢ A new customer arrives: I want a sandwich! ā€¢ Another process starts ā€¢ Fetches the ingredients ā€¢ Prepares the sandwich ā€¢ Hereā€™s your sandwich ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ
  • 49. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ
  • 50. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž
  • 51. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ
  • 52. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 53. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“
  • 54. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ
  • 55. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸ„Ŗ
  • 56. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ
  • 57. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ
  • 58. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ
  • 59. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ ! šŸ„Ŗ šŸ“ šŸž
  • 60. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ ! šŸ„Ŗ šŸ“ šŸž šŸ„œ
  • 61. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ ! šŸ„Ŗ šŸ“ šŸž šŸ„œ šŸ„Ŗ šŸ“
  • 62. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ ! šŸ„Ŗ šŸ“ šŸž šŸ„œ šŸ„Ŗ šŸ“ šŸ„Ŗ
  • 63. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž ! šŸ„Ŗ šŸ„Ŗ šŸ„œ ! šŸ„Ŗ šŸ“ šŸž šŸ„œ šŸ„Ŗ šŸ“ šŸ„Ŗ šŸ„Ŗ
  • 64. @joel__lord #iJS18 Event Loop (NodeJS) ā€¢ I want a sandwich! ā€¢ Sure ā€¢ ā€œWorker, Make a sandwichā€ ā€¢ A new customer arrives: I want a sandwich! ā€¢ Sure ā€¢ ā€œOther worker, make a sandwichā€ ā€¢ Here is your sandwich customer 1 ! šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ šŸž šŸ„œ šŸ“ šŸ„Ŗ ! šŸ„Ŗ ! šŸ„Ŗ šŸ„Ŗ šŸ„Ŗ šŸ„Ŗ
  • 66. @joel__lord #iJS18 Code let PBnJMaker = require("./pbnjmaker"); PBnJMaker.fetchBread(); PBnJMaker.fetchPeanutButter(); PBnJMaker.fetchJam(); PBnJMaker.spreadPeanutButter(); PBnJMaker.spreadJam(); let result = PBnJMaker.closeSandwich(); console.log("Eat that " + result);
  • 69. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous // //Synchronous let array = [1,2,3]; console.log("begin"); array.map((i) => {console.log(i)}); console.log("after");
  • 70. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous
  • 71. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous //Asynchronous console.log("begin"); fs.readFile("./cb.txt", (err, data) => { console.log(ā€œFile contentā€); }); console.log("after");
  • 72. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous
  • 73. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous //Asynchronous console.log("begin"); fs.readFile("./cb.txt", (err, data) => { console.log(ā€œFile contentā€); }); console.log("after");
  • 74. @joel__lord #iJS18 What is a callback ! Simply a function as an argument to a function ! Could be synchronous or asynchronous //Asynchronous ..................... ....................... (err, data) => { console.log(ā€œFile contentā€); }.. .....................
  • 75. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop console.log("begin"); fs.readFile("./cb.txt", (err, data) => { console.log(data); }); console.log("after");
  • 76. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop fs.readFile("./cb.txt", (err, data) => { console.log(data); }); console.log("after");
  • 77. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop console.log("after"); (err, data) => { console.log(data); }
  • 78. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop (err, data) => { console.log(data); }
  • 79. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop (err, data) => { console.log(data); }
  • 80. @joel__lord #iJS18 What is a callback Asynchronous callback and the event loop
  • 81. @joel__lord #iJS18 Code let PBnJMaker = require("../pbnjmaker"); PBnJMaker.fetchBread(() => { PBnJMaker.fetchPeanutButter(() => { PBnJMaker.fetchJam(() => { PBnJMaker.spreadPeanutButter(() => { PBnJMaker.spreadJam(() => { PBnJMaker.closeSandwich((err, output) => { console.log("Eat that " + output); }); }); }); }); }); });
  • 83. @joel__lord #iJS18 Callbacks ! It works! ! butā€¦ let PBnJMaker = require("../pbnjmaker"); PBnJMaker.simulateError(); PBnJMaker.fetchBread((err) => { if (err) { console.log("An error occurred while fetching the ingredients"); } else { PBnJMaker.fetchPeanutButter((err) => { if (err) { console.log("An error occurred while fetching the ingredients"); } else { PBnJMaker.fetchJam((err) => { if (err) { console.log("An error occurred while fetching the ingredients"); } else { PBnJMaker.spreadPeanutButter((err) => { if (err) { console.log("An error occurred whileā€¦ the sandwich"); } else { PBnJMaker.spreadJam((err) => { if (err) { console.log("An error occurred ā€¦ the sandwich"); } else { PBnJMaker.closeSandwich((err, result) => { if (err) { console.log("An error occurred"); } else { console.log("Eat that " + result); } }); } }); } }); } }); } }); } });
  • 84. @joel__lord #iJS18 Callback Hell let PBnJMaker = require("../pbnjmaker"); PBnJMaker.simulateError(); PBnJMaker.fetchBread((err) => { if (err) { console.log("An error occurred while fetching the ingredients"); } else { PBnJMaker.fetchPeanutButter((err) => { if (err) { console.log("An error occurred whileā€¦ ingredients"); } else { PBnJMaker.fetchJam((err) => {
  • 86. @joel__lord #iJS18 Step by step Parallel events šŸ“šŸž šŸ„œ šŸ„Ŗ šŸž šŸ„œ šŸ„Ŗ šŸ“
  • 87. @joel__lord #iJS18 Code let PBnJMaker = require("../pbnjmaker");
  • 91. @joel__lord #iJS18 Code function handleIngredients(err) { if (err) return console.log(ā€œErrorā€); ingredients++; if (ingredients === 3) { prepareSandwich(); } }
  • 93. @joel__lord #iJS18 Code function preparationStepCompleted(err) { if (err) return console.log(ā€œError"); steps++; if (steps === 2) { completeSandwich(); } }
  • 94. @joel__lord #iJS18 Code function completeSandwich(err) { PBnJMaker.closeSandwich((err, result) => { if (err) { console.log("An error occurred"); } else { console.log("Eat that " + result); } }); }
  • 98. @joel__lord #iJS18 What is a promise? ! A representation of a callback ! Returns a .then() method ! Error handling simplified //Asynchronous console.log("begin"); asyncPromise().then(onSuccess, onFailure); console.log("after");
  • 99. @joel__lord #iJS18 What is a promise? ! A representation of a callback ! Returns a .then() method ! Error handling simplified //Asynchronous console.log("begin"); fs.readFile("./cb.txt") .then((data) => { console.log(data); }, (err) => { console.log(err); }); console.log("after");
  • 100. @joel__lord #iJS18 What is a promise? ! A representation of a callback ! Returns a .then() method ! Error handling simplified //Asynchronous console.log("begin"); fs.readFile("./cb.txt") .then((data) => { console.log(data); }).catch((err) => { console.log(err); }); console.log("after");
  • 104. @joel__lord #iJS18 Code Result PBnJMaker.fetchBread().then(() => { return PBnJMaker.fetchPeanutButter(); })
  • 105. @joel__lord #iJS18 Code Result PBnJMaker.fetchBread().then(() => { return PBnJMaker.fetchPeanutButter(); }).then(() => {
  • 106. @joel__lord #iJS18 Code Result PBnJMaker.fetchBread().then(() => { return PBnJMaker.fetchPeanutButter(); }).then(() => { return PBnJMaker.fetchJam();
  • 107. @joel__lord #iJS18 Code Result }).then(() => { return PBnJMaker.spreadPeanutButter();
  • 108. @joel__lord #iJS18 Code Result }).then(() => { return PBnJMaker.spreadJam();
  • 109. @joel__lord #iJS18 Code Result }).then(() => { return PBnJMaker.closeSandwich();
  • 110. @joel__lord #iJS18 Code Result }).then((result) => { console.log("Eat that " + result);
  • 112. @joel__lord #iJS18 Code Result }).catch((err) => { console.log("Error with ingredients");
  • 113. @joel__lord #iJS18 Code Result }).catch((err) => { console.log("Error with ingredients"); }).catch((err) => { console.log(ā€œError preparingā€); }).catch((err) => { console.log(ā€œError somewhereā€);
  • 115. @joel__lord #iJS18 Aggregate functions ! .all() ! .race() let PBnJMaker = require("../pbnjmaker"); Promise.all([ PBnJMaker.fetchBread(), PBnJMaker.fetchPeanutButter(), PBnJMaker.fetchJam()]) .then(() => { return Promise.all([ PBnJMaker.spreadPeanutButter(), PBnJMaker.spreadJam()]); }).then(() => { return PBnJMaker.closeSandwich(); }).then((result) => { console.log("Eat that " + result); });
  • 116. @joel__lord #iJS18 Aggregate functions ! .all() ! .race() let PBnJMaker = require("../pbnjmaker"); Promise.all([ PBnJMaker.fetchBread(), PBnJMaker.fetchPeanutButter(), PBnJMaker.fetchJam()]) .then(() => { return Promise.all([ PBnJMaker.spreadPeanutButter(), PBnJMaker.spreadJam()]); }).then(() => { return PBnJMaker.closeSandwich(); }).then((result) => { console.log("Eat that " + result); });
  • 117. @joel__lord #iJS18 Aggregate functions ! .all() ! .race() let PBnJMaker = require("../pbnjmaker"); Promise.all([ PBnJMaker.fetchBread(), PBnJMaker.fetchPeanutButter(), PBnJMaker.fetchJam()]) .then(() => { return Promise.all([ PBnJMaker.spreadPeanutButter(), PBnJMaker.spreadJam()]); }).then(() => { return PBnJMaker.closeSandwich(); }).then((result) => { console.log("Eat that " + result); });
  • 118. @joel__lord #iJS18 Aggregate functions ! .all() ! .race() let PBnJMaker = require("../pbnjmaker"); Promise.all([ PBnJMaker.fetchBread(), PBnJMaker.fetchPeanutButter(), PBnJMaker.fetchJam()]) .then(() => { return Promise.all([ PBnJMaker.spreadPeanutButter(), PBnJMaker.spreadJam()]); }).then(() => { return PBnJMaker.closeSandwich(); }).then((result) => { console.log("Eat that " + result); });
  • 120. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 121. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 122. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 123. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 124. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 125. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 126. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 127. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 128. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 129. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 130. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 131. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 132. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 133. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 134. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 135. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 136. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } let iteration = iterable(); console.log(iteration.next()); // 3 // Do stuff console.log(iteration.next()); // 2 console.log(iteration.next()); // 1 console.log(iteration.next()); // 0 // More stuff console.log(iteration.next()); // undefined
  • 137. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } for (let iteration of iterable()) { console.log(iteration); } // 3 // 2 // 1 // 0
  • 138. @joel__lord #iJS18 What is a generator? ! An iterable function ! ā€œPausesā€ the execution of a function function* iterable() { let i = 4; while(i--) { yield i; } } for (let iteration of iterable()) { console.log(iteration); } // 3 // 2 // 1 // 0
  • 139. @joel__lord #iJS18 Code Result let PBnJMaker = require("../pbnjmaker"); PBnJMaker.verbose(); function* makePBnJ() { yield PBnJMaker.fetchBread; yield PBnJMaker.fetchPeanutButter; yield PBnJMaker.fetchJam; yield PBnJMaker.spreadPeanutButter; yield PBnJMaker.spreadJam; yield PBnJMaker.closeSandwich; } for (let step of makePBnJ()) { step(); } console.log("Eat that sandwich");
  • 140. @joel__lord #iJS18 Async Generators ! Combining the power of promises and generators module.exports = (makeGenerator) => { let generator = makeGenerator.apply(this, arguments); function handle(result) { // generator returns {done: [Boolean], value: [Any}} if (result.done) return Promise.resolve(result.value); return Promise.resolve(result.value).then(function(res) { return handle(generator.next(res)); }, function(err) { return handle(generator.throw(err)); }); } try { return handle(generator.next()); } catch(e) { return Promise.reject(e); } };
  • 141. @joel__lord #iJS18 Code Result let PBnJMaker = require("../pbnjmaker"); let async = require("../async"); function* makePBnJ() { yield PBnJMaker.fetchBread(); yield PBnJMaker.fetchPeanutButter(); yield PBnJMaker.fetchJam(); yield PBnJMaker.spreadPeanutButter(); yield PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } async(makePBnJ).then((result) => { console.log("Eat that " + result); });
  • 142. @joel__lord #iJS18 Code Result let PBnJMaker = require("../pbnjmaker"); let async = require("../async"); function* makePBnJ() { yield PBnJMaker.fetchBread(); yield PBnJMaker.fetchPeanutButter(); yield PBnJMaker.fetchJam(); yield PBnJMaker.spreadPeanutButter(); yield PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } async(makePBnJ).then((result) => { console.log("Eat that " + result); });
  • 144. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 145. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 146. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 147. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 148. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 149. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 150. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 151. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 152. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 153. @joel__lord #iJS18 What is async/await? ! Newly introduced in ES8 (ES2017) ! Natural evolution of generators and promises let PBnJMaker = require("../pbnjmaker"); async function makePBnJ() { await PBnJMaker.fetchBread(); await PBnJMaker.fetchPeanutButter(); await PBnJMaker.fetchJam(); await PBnJMaker.spreadPeanutButter(); await PBnJMaker.spreadJam(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log(ā€œEat that " + result) });
  • 154. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 155. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 156. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 157. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 158. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 159. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 160. @joel__lord #iJS18 What is async/await? ! Very easy to parallelize processes let PBnJMaker = require("../pbnjmaker"); async function getIngredients() { let p1 = PBnJMaker.fetchBread(); let p2 = PBnJMaker.fetchPeanutButter(); let p3 = PBnJMaker.fetchJam(); return await p1 + await p2 + await p3; } async function prepareSandwich() { let p1 = PBnJMaker.spreadPeanutButter(); let p2 = PBnJMaker.spreadJam(); return await p1 + await p2; } async function makePBnJ() { await getIngredients(); await prepareSandwich(); return PBnJMaker.closeSandwich(); } makePBnJ().then((result) => { console.log("Eat that " + result) });
  • 161. @joel__lord #iJS18 Async / Await Programatically define your steps let PBnJMaker = require("../pbnjmaker"); let ingredients = ["Bread", "PeanutButter", "Jam"]; let steps = ingredients.map((i) => `fetch${i}`); steps.push(...["spreadPeanutButter", "spreadJam"]); async function makePBnJ(todo) { for (var i = 0; i < todo.length; i++) { await PBnJMaker[todo[i]](); } return PBnJMaker.closeSandwich(); } makePBnJ(steps).then((result) => { console.log(ā€œEat that " + result) });
  • 163. @joel__lord #iJS18 Events in the browser ! At the core of the original Javascript ! window.onready = ā€¦ ! button.onclick = ā€¦
  • 164. @joel__lord #iJS18 Node Event Emitter ! In node, you can use the event emitter ! Create you own events for a library
  • 165. @joel__lord #iJS18 Node Event Emitter ! In node, you can use the event emitter ! Create you own events for a library
  • 169. @joel__lord #iJS18 RxJS ! Manipulate data, synchronous or asynchronous as streams ! Manipulate streams like arrays
  • 173. @joel__lord #iJS18 Summary Asynchronous patterns ! The Event Loop ! Callbacks ! Promises ! Generators ! Async/Await ! Events ! Reactive Stream
  • 174. @joel__lord #iJS18 Summary Asynchronous patterns ! The Event Loop ! Callbacks ! Promises ! Generators ! Async/Await ! Events ! Reactive Stream ! ā€¦. How to make a PBnJ sandwich!
  • 175. Asynchronicity: concurrency. A tale of iJS, London, UK April 11, 2018 @joel__lord joellord Special thanks to @tomasz_ducinĀ for the inspiration