1

Error: Function returned undefined, expected Promise or value

exports.openStore = functions.pubsub.schedule('0 15 * * *') .timeZone('America/Los_Angeles') .onRun((context) => { admin.database().ref('/ControlPanel').update({open: true}); console.log('Open the Store!'); }); 

What is the best way to return a promise or value with a scheduled cloud function.

1 Answer 1

4

Just return the only promise you're creating:

exports.openStore = functions.pubsub.schedule('0 15 * * *') .timeZone('America/Los_Angeles') .onRun((context) => { console.log('Open the Store!'); return admin.database().ref('/ControlPanel').update({open: true}); }); 

If you're new to JavaScript, Cloud Functions might not be the best way to learn, as you will be required to understand asynchronous programming in order to make things work the way you want.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks i'll mark it correct and go with this. I was just making sure of the best approach.
It looks like you are the guy from the firebase videos :). Thanks again. I'm trying to convert all my Javascript functions to typescript so I can use the async await. I keep running into Parameter 'xxx' implicitly has an 'any' type. when I try to pass parameters. Trying to determine if its safe to set ""noImplicitAny": false" or try and rewrite my code in some other way. Thanks again for everything you do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.