Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
52 views
6 pages
Timer
Uploaded by
snehavenkatt27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Timer For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
52 views
6 pages
Timer
Uploaded by
snehavenkatt27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Timer For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Timer For Later
You are on page 1
/ 6
Search
Fullscreen
oe Node 3S 227 2. Cancelling Timers: It is used to cancel the scheduled timer « clearlmmediate(): It is used to stop an immediateObject, as created by ~ setimmediate Clearinterval(): It is used to stop an intervalObject, as created by setinterval, _e clearTimeout(): It prevents a timeoutObject, as created by setTimeout 2.7.1 Scheduling Timers 1. setTimeout() setTimeout() method is used to execute a piece of code after a specified time. . © The setTimeout() function takes three arguments: ¢ First: the function to be run (user defined function) + Second: the delay in milliseconds (time parameter to delay execution) « Third (optional): an argument to be passed to the function The time parameter, which is optional to pass, stores ‘the time in milliseconds (1 second = 1000 milliseconds). The code will . executed after the time that is passed as the argument. . Syntax: ea let timeoutld = setTimeout(funcl, delay, argument!, argument2, ...]);// syntax let timeoutld = setTimeout(func{, delay}); // option 2 let timeoutld = setTimeout(code[, delay]); // option 32.28 Fuh Hache Waly ti Outputs According 10 the above code, the console,log() written in the callback f Will exeoute after 10000 milliseconds, 1.6 10 seconds, 2 setlaterval()s + The setinterval method is similar to the set Timeout) function in + — Hrepoats the specified finetion after a time interval, + A funetion is executed repeatedly after a certain amount of time by the user in this function, * Wrequires three arguments: * First: the function to be executed * Second: the delay in milliseconds * — Third (optional); an argument to be passed to the function Syntax: Jet intervalld = setInterval(callbackFunetion, [delay,, /loption 1 Jet intervalld = setInterval(callbackFunction{, delayDuration)); let intervalld = setInterval(code, [delayDuration]); /option 3 // option 2 setinterval(printSomeStuff, 5000) function print! console.log(*This message is displayed from setini } uf) { Herval method’) Output: ‘The below code will keep on printing the Matement present in console.log() very 5000 milliseconds i.c 5 seconds, ie displayed fr Int pers) is displayed fr petInter method 10 displayed from setty method » displayed from setInts method brine batt Tren aT) vr aes ST} POON TT tio)Node JS 529 3. setimmediate(): « _ setimmediate() method is used to execute code at the end of the loop cycle. e _ setimmediate() method queues its callback on the event loop and any function that is passed to setimmediate method() is executed in the next iteration of the event loop. « _ setimmediate() is similar to setTimeout() with a Oms time delay. « setimmediate() takes two arguments: First: The first argument passed to the setImmediate() method is a function that will be executed. ¢ Second (optional): the function’s parameter Synatx: let immediateld = setmmediate(callbackFunction, [param], param2, ...}); Jet immediateld = setImmediate(callbackFunction); ial Example: setImmediate(printSomething) function printSomething(){ console.log(‘This message is displayed immediately by setlmmediate()”) } Output: The above console.log() is printed as soon as the code is executed. Boil hea 2.1.2 Cancelling Timers 1, ¢learTimeout(): * The clearInterval() function halts the interval object created by the SetInterval() function: y * i, The clearTimeout() method allows to destroy/ cance! the timer created by the set Timeout object. * The seTimeout() methods returns anid (number) which is stored ina variable and that variable is passed to clearTimeout() method which clears the timer,2,30 Full Stack Web Develop, ' * — The object returned when the timeout is scheduled, it exports the timeout and timeout.unref() functions that help us control the behavior. ° The timeout.hasRef() method, it returns true; the timeout object keeps the | Event Loop active, : * The timeout.ref() method returns the reference to timeout and Fequests no, Not to exit the Event Loop as long as the timeout object is active an, timeout.unref{) method on being called will not require the Node} Loop to remain active. * The timeout.refresh() method allows refreshing a timer without alloca new Javascript object, Example: . var timeoutObject; timeoutObject = setTimeout(callBack, 10000) function callBack(){ console.log(“This message is from setTimeout method”) } function stopTimeout(){ clearTimeout(timeoutObject) 3 Output: Mush Mr tote y be ede hen Meee et SEES | 2. clearInterval(); ° The clearInterval() method is us ed to cancel the object create: setlnterval method(), * — The id which is associated with th eat e setInterval() method is used to !<" timer set by the method,Node 3S 2.31 Example: var intervalObject; intervalObject = setinterval(printSomeStuff, 5000) function printSomeStuff(){ console.log(*This message is displayed from setInterval method’) } function stopIntervalObject(){ clearInterval(intervalObject) } Output: This message is displayed from setInterval method This message is displayed from setInterval method Beebe eure Sei} displayed from setInterval method This message is displayed from setInterval method This message is displayed from setInterval method message is-displayed from setinterval method 3. clearImmediate(): The clearlmmediate() object is used in node.js to clear the timer set by SetImmediate() method. The clearlmmediate() method is used to cancel /destroy the object which is created by the setImmediate() method. The object returned when the immediate is scheduled, it exports the immediate.ref() and immediate.unref() functions that help us control the behavior. The immediate.hasRef{) method, it returns true; the immediate object keeps the Event Loop active. The immediate.ref() method returns the reference to immediate and requests node not to exit the Event Loop as long as the immediate object is active and the immediate.unref{) method on being called will not require the Nodejs Event Loop to remain active,
You might also like
NodeJS Interview Questions
PDF
No ratings yet
NodeJS Interview Questions
20 pages
Apis and Javascript
PDF
No ratings yet
Apis and Javascript
68 pages
Devops Unit-1 Anna University
PDF
100% (5)
Devops Unit-1 Anna University
56 pages
Asynchronous Javascript
PDF
No ratings yet
Asynchronous Javascript
8 pages
JavaScript + CSS M3L2
PDF
No ratings yet
JavaScript + CSS M3L2
88 pages
Business Analytics Anna University
PDF
No ratings yet
Business Analytics Anna University
40 pages
Asynchronous Programming: The Complete Javascript Course
PDF
No ratings yet
Asynchronous Programming: The Complete Javascript Course
41 pages
Slides 1
PDF
No ratings yet
Slides 1
41 pages
Async Basic
PDF
No ratings yet
Async Basic
22 pages
Timing Events
PDF
No ratings yet
Timing Events
13 pages
Javascript Timer Function
PDF
No ratings yet
Javascript Timer Function
5 pages
Asynchronous Programming in JavaScript - Guide For Beginners
PDF
No ratings yet
Asynchronous Programming in JavaScript - Guide For Beginners
16 pages
Unit 4 PDF
PDF
No ratings yet
Unit 4 PDF
29 pages
IP
PDF
No ratings yet
IP
26 pages
IP Main Question
PDF
No ratings yet
IP Main Question
20 pages
Javascript Notes - by Prakash
PDF
No ratings yet
Javascript Notes - by Prakash
11 pages
Async Programming, Closures, IIFE
PDF
No ratings yet
Async Programming, Closures, IIFE
23 pages
Promises in Js
PDF
No ratings yet
Promises in Js
21 pages
Lecure 8
PDF
No ratings yet
Lecure 8
22 pages
Timing Function
PDF
No ratings yet
Timing Function
2 pages
Events
PDF
No ratings yet
Events
47 pages
FSD-PPT On Event Js Ode Model
PDF
No ratings yet
FSD-PPT On Event Js Ode Model
11 pages
JavaScript Promises
PDF
No ratings yet
JavaScript Promises
37 pages
Week 6 AsynchronousJS Class Notes
PDF
No ratings yet
Week 6 AsynchronousJS Class Notes
21 pages
Events NBL
PDF
No ratings yet
Events NBL
47 pages
Lecture 11
PDF
No ratings yet
Lecture 11
25 pages
Js Notes
PDF
No ratings yet
Js Notes
15 pages
Lecture 10
PDF
No ratings yet
Lecture 10
18 pages
Ad Js
PDF
No ratings yet
Ad Js
22 pages
JavaScript Timers
PDF
No ratings yet
JavaScript Timers
2 pages
Javascript Timer
PDF
No ratings yet
Javascript Timer
11 pages
Tamás Sallai - Asynchronous Programming Patterns in Javascript - How To Use Async - Await and Promises To Solve Programming Problems-Leanpub (2021)
PDF
No ratings yet
Tamás Sallai - Asynchronous Programming Patterns in Javascript - How To Use Async - Await and Promises To Solve Programming Problems-Leanpub (2021)
135 pages
032 Usestate Hook Practice - en - SRT
PDF
No ratings yet
032 Usestate Hook Practice - en - SRT
7 pages
Asynchronous Programming
PDF
No ratings yet
Asynchronous Programming
16 pages
Code Flow
PDF
No ratings yet
Code Flow
3 pages
Lec 5
PDF
No ratings yet
Lec 5
8 pages
9 JavaScript Callbacks Promises Async and Await
PDF
No ratings yet
9 JavaScript Callbacks Promises Async and Await
17 pages
JavaScript Call Stack Basics
PDF
No ratings yet
JavaScript Call Stack Basics
10 pages
Callbacks in JavaScript - A Comprehensive Guide
PDF
No ratings yet
Callbacks in JavaScript - A Comprehensive Guide
9 pages
TW 09
PDF
No ratings yet
TW 09
7 pages
Asynchronous JavaScript
PDF
No ratings yet
Asynchronous JavaScript
14 pages
Advanced JavaScript
PDF
No ratings yet
Advanced JavaScript
16 pages
My Javscript Interview Experince
PDF
No ratings yet
My Javscript Interview Experince
7 pages
Advance Js PPT
PDF
No ratings yet
Advance Js PPT
18 pages
Business Analytics
PDF
No ratings yet
Business Analytics
27 pages
Fet P10
PDF
No ratings yet
Fet P10
3 pages
Javascript Day-3
PDF
No ratings yet
Javascript Day-3
5 pages
JavaScript Interview Guide - Preview-1
PDF
No ratings yet
JavaScript Interview Guide - Preview-1
49 pages
javascript async عمليات الاسترجاعات غير المتزامنة
PDF
No ratings yet
javascript async عمليات الاسترجاعات غير المتزامنة
9 pages
JavaScript Advance
PDF
No ratings yet
JavaScript Advance
19 pages
Unit 5 Updated
PDF
No ratings yet
Unit 5 Updated
18 pages
34 BasicCallback JS
PDF
No ratings yet
34 BasicCallback JS
3 pages
Node - JS: SetImmediate vs. Process - Nexttick - A Journey in Open-Source Software Land.
PDF
No ratings yet
Node - JS: SetImmediate vs. Process - Nexttick - A Journey in Open-Source Software Land.
3 pages
NODEjs Lecture 2
PDF
No ratings yet
NODEjs Lecture 2
23 pages
Global Vs Local Installation: NPM Install Express
PDF
No ratings yet
Global Vs Local Installation: NPM Install Express
20 pages
Untitled Document
PDF
No ratings yet
Untitled Document
14 pages
Asynchronous Programming in JavaScript
PDF
No ratings yet
Asynchronous Programming in JavaScript
8 pages
NodeJS Notes 01
PDF
No ratings yet
NodeJS Notes 01
6 pages
Js Revison Topics
PDF
No ratings yet
Js Revison Topics
9 pages
Unit 2 It3501
PDF
No ratings yet
Unit 2 It3501
5 pages
Interview Questions
PDF
No ratings yet
Interview Questions
8 pages
JavaScript Asynchronous
PDF
No ratings yet
JavaScript Asynchronous
4 pages
DC SET A Anna University
PDF
No ratings yet
DC SET A Anna University
2 pages
Event in Full Stack Web Development
PDF
No ratings yet
Event in Full Stack Web Development
8 pages