function successCallback(result) {
console.log(`Audio file ready at URL: ${result}`);
}
function failureCallback(error) {
console.error(`Error generating audio file: ${error}`);
}
createAudioFileAsync(audioSettings, successCallback, failureCallback);Using promises / notebook
Using promises
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
createAudioFileAsync(audioSettings).then(successCallback, failureCallback);const promise = doSomething();
const promise2 = promise.then(successCallback, failureCallback);> function doSomething() {
> return new Promise((resolve) => {
> setTimeout(() => {
> // Other things to do before completion of the promise
> console.log("Did something");
> // The fulfillment value of the promise
> resolve("https://example.com/");
> }, 200);
> });
> }
>doSomething()
.then(function (result) {
return doSomethingElse(result);
})
.then(function (newResult) {
return doThirdThing(newResult);
})
.then(function (finalResult) {
console.log(`Got the final result: ${finalResult}`);
})
.catch(failureCallback);doSomething()
.then((result) => doSomethingElse(result))
.then((newResult) => doThirdThing(newResult))
.then((finalResult) => {
console.log(`Got the final result: ${finalResult}`);
})
.catch(failureCallback);