Skip to content

Commit

Permalink
Fix issue with use of callback for async function (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
caulagi authored and jayair committed Dec 23, 2018
1 parent 76eb8fe commit 1b6face
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ A demo version of this service is hosted on AWS - [`https://z6pv80ao4l.execute-a
And here is the ES7 source behind it

``` javascript
export const hello = async (event, context, callback) => {
const response = {
export const hello = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: `Go Serverless v1.0! ${(await message({ time: 1, copy: 'Your function executed successfully!'}))}`,
input: event,
}),
};

callback(null, response);
};

const message = ({ time, ...rest }) => new Promise((resolve, reject) =>
const message = ({ time, ...rest }) => new Promise((resolve, reject) =>
setTimeout(() => {
resolve(`${rest.copy} (with a delay)`);
}, time * 1000)
Expand Down
8 changes: 3 additions & 5 deletions handler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
export const hello = async (event, context, callback) => {
const response = {
export const hello = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: `Go Serverless v1.0! ${(await message({ time: 1, copy: 'Your function executed successfully!'}))}`,
}),
};

callback(null, response);
};

const message = ({ time, ...rest }) => new Promise((resolve, reject) =>
const message = ({ time, ...rest }) => new Promise((resolve, reject) =>
setTimeout(() => {
resolve(`${rest.copy} (with a delay)`);
}, time * 1000)
Expand Down

0 comments on commit 1b6face

Please sign in to comment.