Callbacks
One approach to asynchronous programming is to make functions that perform a slow action take an extra argument, a callback
function. The action is started, and when it finishes, the callback function is called with the result.
As an example, the setTimeout
function, available both in Node.js and in browsers, waits a given number of milliseconds (a second is a thousand milliseconds) and then calls a function.
setTimeout (() => console . log ( "Tick" ), 500 );
Waiting is not generally a very important type of work, but it can be useful when doing something like updating an animation or checking whether something is taking longer than a given amount of time.
If you want to change selection, open document below and click on "Move attachment"
Asynchronous Programming :: Eloquent JavaScriptmap shows the nests and their connections: In an astounding example of convergent evolution, crow computers run JavaScript. In this chapter we’ll write some basic networking functions for them. <span>Callbacks One approach to asynchronous programming is to make functions that perform a slow action take an extra argument, a callback function. The action is started, and when it finishes, the callback function is called with the result. As an example, the setTimeout function, available both in Node.js and in browsers, waits a given number of milliseconds (a second is a thousand milliseconds) and then calls a function. setTimeout(() => console.log("Tick"), 500); Waiting is not generally a very important type of work, but it can be useful when doing something like updating an animation or checking whether something is taking longer than a given amount of time. Performing multiple asynchronous actions in a row using callbacks means that you have to keep passing new functions to handle the continuation of the computation after the actions. Most Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details