This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncFunc1 () { | |
console.log("Выполняюсь 1"); | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 200 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
console.log("Выполняюсь 2"); | |
return new Promise(function(resolve, reject) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asyncFunc1().then(function( data ) { | |
console.log( data.message ); | |
return asyncFunc2(); | |
}).then(function( data_2 ) { | |
console.log( data_2.message ); | |
return asyncFunc3(); | |
}).then(function( data_3 ) { | |
console.log( data_3.message ); | |
// Тут делаем наши дела после того, как все функции отработали |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function startAsync() { | |
let data_1 = await asyncFunc1(); // Функция работает как синхронная | |
let data_2 = await asyncFunc2(); // Затем эта функция работает как синхронная | |
let data_3 = await asyncFunc3(); // Наконец эта функция работает как синхронная | |
// Делаем то, что хотели сделать лишь при завершении работы всех трёх функций | |
console.log(data1.message, data2.message, data3.message); | |
}; | |
startAsync(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asyncFunc1().then(function( data ) { | |
console.log( data.message ); // Выводим результат первой функции | |
asyncFunc2().then(function( data ) { | |
console.log( data.message ); // Выводим результат второй функции | |
asyncFunc3().then(function( data ) { | |
console.log( data.message ); // Выводим результат третьей функции | |
// Тут делаем наши дела после того, как все функции отработали | |
console.log("Всё!"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncFunc1 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 300 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "Second done!"}), 200 ); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncFunc1 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 300 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "Second done!"}), 200 ); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log "Hello from Gist!" |
NewerOlder