Skip to content

Commit aa3344a

Browse files
committed
Adding control flow
1 parent 2443d5b commit aa3344a

File tree

12 files changed

+449
-25
lines changed

12 files changed

+449
-25
lines changed

.eleventy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = function(eleventyConfig) {
1515
eleventyConfig.addPassthroughCopy("js");
1616
eleventyConfig.addPassthroughCopy("CNAME");
1717
eleventyConfig.addLayoutAlias("default", "default.njk");
18+
eleventyConfig.addLayoutAlias("post", "post.njk");
1819
return {
1920
passthroughFileCopy: true
2021
};

TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default.njk
2+
layout: default
33
title: Your post title
44
---
55

buffers-and-streams/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default.njk
2+
layout: default
33
title: Buffers and Streams
44
---
55

cheatsheet/index.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
11
---
2-
layout: default.njk
2+
layout: default
33
title: Node Cheat Sheet
44
---
55

6+
## [Control Flow](#control-flow)
7+
8+
### Callback pattern
9+
10+
```
11+
function foo(val1, val2, callback) {
12+
...
13+
callback();
14+
}
15+
```
16+
17+
### Promise pattern
18+
19+
```
20+
function foo(ok) {
21+
return new Promise(resolve, reject) {
22+
if (ok) {
23+
resolve('success');
24+
} else {
25+
reject('boo');
26+
}
27+
}
28+
}
29+
30+
foo()
31+
.then(res => {
32+
console.log(res);
33+
})
34+
.catch(err => {
35+
throw err;
36+
})
37+
```
38+
39+
### Async/Await
40+
41+
```
42+
async function callFoo() {
43+
try {
44+
const result = await foo(true);
45+
} catch(err) {
46+
throw err;
47+
}
48+
}
49+
```
50+
651
## [Events](#events)
752

853
Class: events.EventEmitter

child-processes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default.njk
2+
layout: default
33
title: Child Processes
44
---
55

0 commit comments

Comments
 (0)