Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs11-async
documents
Commits
56f8bc88
Commit
56f8bc88
authored
4 years ago
by
dbi
Browse files
Options
Download
Email Patches
Plain Diff
Fix typos in callbacks.md
parent
baf236bb
master
1 merge request
!1
Fix typos in callbacks.md
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notes/callbacks/callbacks.md
+3
-3
notes/callbacks/callbacks.md
with
3 additions
and
3 deletions
+3
-3
notes/callbacks/callbacks.md
100644 → 100755
View file @
56f8bc88
...
...
@@ -134,7 +134,7 @@ setTimeout(() => {
console
.
log
(
'
3 seconds have passed
'
)
},
3000
)
```
The fact that
`setTimeout()`
is asynchronous means it returns immediately, without witing for the time interval.
The fact that
`setTimeout()`
is asynchronous means it returns immediately, without w
a
iting for the time interval.
For example, the following code displays
`Timeout started`
immediately and
`Timeout ended`
after 1 second:
```
js
setTimeout
(()
=>
{
...
...
@@ -161,7 +161,7 @@ In general, this requires us to create the next asynchronous event *inside* the
As a concrete example, let's simulate a "random walk" on a grid.
At each step, we randomly move left, right, up, or down, and we count the total number of times we have visited each grid square.
To run an asynchronous action after another one finshes, we
*nest it inside the previous callback*
.
To run an asynchronous action after another one fin
i
shes, we
*nest it inside the previous callback*
.
Here is a
[
first attempt
](
walk1.html
)
that only moves 3 times.
```
js
// ... (the full code is at the link above)
...
...
@@ -226,7 +226,7 @@ walkFrom({row: Math.floor(SIZE / 2), col: Math.floor(SIZE / 2)})
We have seen two examples of asynchronous standard library functions in JavaScript: handling user input and waiting for time.
With both of them, we define a function that we want to get called when something happens.
This structure is common to any asynchronous function; the function passed in to run when it finishes is refered to as the "callback function".
This structure is common to any asynchronous function; the function passed in to run when it finishes is refer
r
ed to as the "callback function".
It is up to the browser (or Node.js) to ensure that the callbacks we provide get called at the right times.
We have also looked at some of the primary ways to combine asynchronous actions.
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help