gpt4 book ai didi

java - Firebase SetValue() 和 SetValueAsync() 方法之间有什么区别以及何时使用它们?

转载 作者:行者123 更新时间:2023-12-02 09:21:47 25 4
gpt4 key购买 nike

官方文档没有显示 SetValue() 和 SetValueAsync() 之间有任何有意义的区别:

https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/database/DatabaseReference

1. void setValue(Object value, DatabaseReference.CompletionListener listener)

Description: Set the data at this location to the given value.


2. ApiFuture<Void> setValueAsync(Object value)

Description: Set the data at this location to the given value.

使用“异步”方法有什么影响?

“ApiFuture”的含义是什么?

我打算使用这些方法来保存字符串。这根绳子有一页书那么大。推荐的实现方法是什么?

最佳答案

非异步方法将阻塞,直到操作完成。

异步方法是异步的并且立即返回。该工作在一段时间后完成,可以通过返回的 ApiFuture 进行跟踪。

Learn about asynchronous operations with the Firebase Admin Java SDK .

Learn about ApiFuture 。您向其添加一个监听器,以便查明操作何时完成。

异步和非异步方法都可以正常工作。选择最适合您情况的一个。

关于java - Firebase SetValue() 和 SetValueAsync() 方法之间有什么区别以及何时使用它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58644807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com