At the moment I am working on await feature in TIScript.
Await is a way to solve callback / promise “hell” in languages like JavaScript and so Sciter Script:
Consider the following code that uses await:
function setupUsersMottoTask(userName) { try { var user = await request(#get, "http://example.com/user/" + userName); var userMotto = await request(#get, "http://example.com/user/" + user.id + "/avatar"); self.$(#user > .motto).text = userMotto; } catch (e) { self.$(#user > .motto).text = "motto unavailable"; } } setupUsersMottoTask("monster"); // runs asynchronously as it is a Task function.
Without await
that code above would look like as a ladder of callbacks and error handlers.
Essentially await
linearize asynchronous code making it running as normal sequential code.
In Sciter Script any function that uses await
inside is automatically declared as asynchronous task function. Invocation of such function starts the task and returns immediately. Such function returns promise and so it’s call can also be used in other awaits.