setTimeout in firebase function

3,860 views
Skip to first unread message

Daesung Park

unread,
Apr 5, 2017, 10:28:41 AM4/5/17
to Firebase Google Group
I am making a game and would like to notify room members of timeout(game end) after a given time elapsed.
All logics are controlled inside firebase function; I am wondering setTimeout will work as expected.

When I tested with setTimeout, it works. But I am not sure if there is any problems.

Can I use setTimeout in firebase function? Or should I use a firebase queue or something else?

Michael Bleigh

unread,
Apr 5, 2017, 11:07:25 AM4/5/17
to Firebase Google Group

You can use setTimeout, but you will continue to incur function execution cost while the timeout runs, and functions have a default max execution time of 60s.


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/af311df4-5d3a-4f51-9cf0-cd8b88bceebd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacob Wenger

unread,
Apr 5, 2017, 12:27:46 PM4/5/17
to fireba...@googlegroups.com
If you just want to have a synced timer across a bunch of client devices, you don't need Cloud Functions at all. You can use the Realtime Database clock skew APIs (web, Android, iOS).

Cheers,
Jacob

On Wed, Apr 5, 2017 at 8:07 AM, 'Michael Bleigh' via Firebase Google Group <fireba...@googlegroups.com> wrote:

You can use setTimeout, but you will continue to incur function execution cost while the timeout runs, and functions have a default max execution time of 60s.

On Wed, Apr 5, 2017, 7:28 AM Daesung Park <gra...@gmail.com> wrote:
I am making a game and would like to notify room members of timeout(game end) after a given time elapsed.
All logics are controlled inside firebase function; I am wondering setTimeout will work as expected.

When I tested with setTimeout, it works. But I am not sure if there is any problems.

Can I use setTimeout in firebase function? Or should I use a firebase queue or something else?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/af311df4-5d3a-4f51-9cf0-cd8b88bceebd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Doug Stevenson

unread,
Apr 5, 2017, 5:13:33 PM4/5/17
to Firebase Google Group
I think the feature request hidden the original question is to have the ability to schedule a delayed trigger of a function after some arbitrary amount of time.  This would allow the server to trigger a timeout or some event rather than depending on clients to all do it accurately.  Pubsub schedules functions for ASAP execution, and using a cron scheduler gives you periodic execution, but we don't have anything to say "run this function x second from now".

Doug


On Wednesday, April 5, 2017 at 9:27:46 AM UTC-7, Jacob Wenger wrote:
If you just want to have a synced timer across a bunch of client devices, you don't need Cloud Functions at all. You can use the Realtime Database clock skew APIs (web, Android, iOS).

Cheers,
Jacob
On Wed, Apr 5, 2017 at 8:07 AM, 'Michael Bleigh' via Firebase Google Group <fireba...@googlegroups.com> wrote:

You can use setTimeout, but you will continue to incur function execution cost while the timeout runs, and functions have a default max execution time of 60s.

On Wed, Apr 5, 2017, 7:28 AM Daesung Park <gra...@gmail.com> wrote:
I am making a game and would like to notify room members of timeout(game end) after a given time elapsed.
All logics are controlled inside firebase function; I am wondering setTimeout will work as expected.

When I tested with setTimeout, it works. But I am not sure if there is any problems.

Can I use setTimeout in firebase function? Or should I use a firebase queue or something else?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/af311df4-5d3a-4f51-9cf0-cd8b88bceebd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Nick Okunew

unread,
Apr 6, 2017, 10:00:48 AM4/6/17
to Firebase Google Group
Cron and scheduled tasks are both sorely missing from GCP as a whole - the main use for firebase is the abilityy to defer tasks in time (as in this case) and to ensure that required functions have executed (in case a real time trigger failed)

Daesung Park

unread,
Apr 6, 2017, 10:01:44 AM4/6/17
to Firebase Google Group
Do you mean "gameDuration" is also calculated as CPU-seconds? If so, I can't use setTimeout. 

  var gameDuration = 100000;
  setTimeout(function notifyTimeover() { }, gameDuration);

Thanks for the info.

Daesung

2017년 4월 6일 목요일 오전 12시 7분 25초 UTC+9, Michael Bleigh 님의 말:

Damien Lebrun

unread,
Apr 6, 2017, 8:46:11 PM4/6/17
to Firebase Google Group
Google App Engine support cron jobs and queue with tasks that can be delayed. Hopefully it will be added to cloud function; AWS lambda support it in more direct way.

Nick Okunew

unread,
Apr 8, 2017, 10:56:55 AM4/8/17
to Firebase Google Group
Indeed it does but it's fairly restrictive:
Minimum granularity is 1 minutes
It can only call a GAE app, not any endpoint in your cloud project
It had to be deployed on your default service

Damien Lebrun

unread,
Apr 9, 2017, 10:57:02 AM4/9/17
to Firebase Google Group
On Saturday, 8 April 2017 15:56:55 UTC+1, Nick Okunew wrote:
Minimum granularity is 1 minutes

 
It can only call a GAE app, not any endpoint in your cloud project

You can create a cron job or a delayed task to notify anything via a google cloud pub/sub topic or a http request. You can keep that GAE app thin and use it as a proxy for other gcloud services.

Reply all
Reply to author
Forward
0 new messages