Multi-Thread Firebase function

99封情书 提交于 2020-05-29 07:07:10

问题


So I am developing a Firebase function that accepts requests from users and updates few nodes under a branch these users are listening to.

My issue is if the function receives two client requests at the same time, that triggers two functions to execute and update the data at the same time.

I know this is typically solved by a transaction, but my updates are done on various nodes not only one value (i.e counter).

In a traditional multi-threading programming, this problems is solved by locking the code from executing so it can only be executed by one thread, where the next one resumes when the current one finishes.

Is this an option in Firebase Functions? If so, how can it be done?


回答1:


There is currently no threading in Cloud Functions in any environment, both node and python included. You should not be depending on process level locking in Cloud Function - use a database transaction to ensure that updates are atomic and consistent. Each of your function invocations is going to be completely isolated from each other.



来源:https://stackoverflow.com/questions/53985802/multi-thread-firebase-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!