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
'use strict'; | |
module.exports.hello = (event, context, callback) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify({ | |
message: 'Go Serverless v1.0! Your function executed successfully!', | |
input: event, | |
}), | |
}; |
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
# Welcome to Serverless! | |
# | |
# This file is the main config file for your service. | |
# It's very minimal at this point and uses default values. | |
# You can always add more config options for more control. | |
# We've included some commented out config examples here. | |
# Just uncomment any of them to get that config option. | |
# | |
# For full config options, check the docs: | |
# docs.serverless.com |
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
let promise = (time) => { | |
return new Promise((res, rej) => { | |
console.log(`Promise ${time} start`) | |
setTimeout(() => { | |
res(`Promise ${time} end`) | |
}, time) | |
}) | |
} |
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
promise(1000) // |-----| | |
.then(msg => { | |
console.log(msg) | |
}) | |
promise(2000) // |-----|-----| | |
.then(msg => { | |
console.log(msg) | |
}) | |
promise(3000) // |-----|-----|-----| | |
.then(msg => { |
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
promise(1000) // |-----| | |
.then((msg) => { | |
console.log(msg) | |
return promise(2000) // |-----|-----| | |
}) | |
.then((msg) => { | |
console.log(msg) | |
return promise(3000) // |-----|-----|-----| | |
}) | |
.then((msg) => { |
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
Promise.all([promise(1000), promise(2000), promise(3000)]) | |
.then((msgs) => { | |
msgs.forEach(msg => { | |
console.log(msg) | |
}); | |
console.log(`End of Promise.all(..)`) | |
}) | |
//Result | |
/* |
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
let tryAsync = async () => { | |
let p1 = promise(1000) // |-----| | |
let p2 = promise(2000) // |-----|-----| | |
let p3 = promise(3000) // |-----|-----|-----| | |
console.log(await p1) | |
console.log(await p2) | |
console.log(await p3) | |
} |
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
let tryAsync = async () => { | |
console.log(await promise(1000)) // |-----| | |
console.log(await promise(2000)) // |-----|-----| | |
console.log(await promise(3000)) // |-----|-----|-----| | |
} | |
tryAsync() | |
//Result | |
/* |
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
let tryAsync = async () => { | |
let msgs = await Promise.all([promise(1000), promise(2000), promise(3000)]) | |
msgs.forEach(msg => { | |
console.log(msg) | |
}); | |
console.log(`End of Promise.all(..)`) | |
} | |
tryAsync() | |
//Result |
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
service: HelloService | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
functions: | |
hello: | |
handler: handler.hello | |
events: | |
- http: | |
path: hello/welcome |
OlderNewer