- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
08-13-2023 07:41 AM - edited 09-29-2023 02:37 AM
Since I started using ServiceNow a few years ago, I was always missing concurrency features like client-side Promises, or C#-like Task - even a basic setTimeout would be sufficient.
A can proudly say, that this search is finally over - introducing "Lib Async":
gs.info("This will execute first");
x_424426_async.setTimeout(function () {
gs.info("This will execute third (after a second wait time)");
}, 1000);
gs.info("This will execute second");
Background Script Output:
Log Output:
More Complex Showcase with Promises:
var firstPromise = new x_424426_async.snPromise(function (resolve, reject) {
gs.info("first promise");
x_424426_async.setTimeout(function () {
resolve("hello");
}, 10000);
});
var secondPromise = new x_424426_async.snPromise(function (resolve, reject) {
gs.info("second promise");
resolve("world");
});
x_424426_async.snPromise.all([firstPromise, secondPromise]).then(function (results) {
gs.info("promise result: " + results.join(","));
})
Background Script Output:
Note that we do not get a result right away because the first promise is resolved after ten second
System Log Output:
Notice the ten second difference between the outputs
- 1,026 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is x_424426_async available OOTB on all instances ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content