Async and await
From SmartBots Developers Docs
Revision as of 18:21, 12 October 2020 by Gg (Talk | contribs) (Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} Async/await is the JavaScript modern approach to the asynchronous programming. The concept may be hard to understand at the very beginning, b...")
Async/await is the JavaScript modern approach to the asynchronous programming. The concept may be hard to understand at the very beginning, but you'll find async functions extremely useful once you get used to them.
Let's take an example from Callbacks and return values page:
var slname = "Smartbots Resident";
Bot.name2key(slname)
.then(function(result) {
// this code will be called when name2key() get completed
console.log("Got the UUID!", result.slkey);
// Oh, now the next step
return Bot.avatarProfile(result.slkey);
})
.then(function(result) {
// this code will be called when avatarProfile() get completed
console.log("Got the age!", result2.age);
Bot.im("Glaznah Gassner", "The age of " + slname + " is " + result2.age);
});
console.log("I've asked for UUID and now waiting for answer");
</syntaxhighligh>
== More examples ==
Check Bot [[../Examples|Playground Examples]] for more code to play with.
{{NavMenu}}
__NOTOC__