Difference between revisions of "Bot Playground/Built-in Functions/process.sleep"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Pauses a program execution.</onlyinclude> <syntaxhighlight lang="javascript"> sleep(timeMs); </syntaxhighlight> {{API Command T...")
 
Line 38: Line 38:
 
2. Within the chain:
 
2. Within the chain:
  
 +
<syntaxhighlight lang="javascript">
 
http.get("https://mysmartbots.com")
 
http.get("https://mysmartbots.com")
 
.then(function() {
 
.then(function() {
Line 47: Line 48:
 
console.log("two");
 
console.log("two");
 
});
 
});
 +
</syntaxhighlight>
  
 
{{NavMenu}}
 
{{NavMenu}}
 
__NOTOC__
 
__NOTOC__

Revision as of 14:59, 14 July 2018

Pauses a program execution.

sleep(timeMs);

Reference

This command accepts the following parameters:

Variable Required Description


Input:
timeMs yes sleep time, ms


Output:
Function returns a Promise with the following data:
success bool true if command completed successfully
error string error string if command has failed

Comments

This function can be used to delay the code execution for a specific time. Note that this function is asynchronous (like the most of javascript), so can't write "doSomething(); sleep(1000); doAfterDelay;". See the examples below.

Examples

The function can be used in two way:

1. Standalone:

console.log("one1");

sleep(2000)
	.then(function() {
		console.log("two2");
	});

2. Within the chain:

http.get("https://mysmartbots.com")
	.then(function() {
		console.log("one");	
		
	return sleep(2000);
	})
	.then(function() {
		console.log("two");
	});