首页
\
问答
\
Kotlin - 如何使用onCompleteListener从Firestore获取数据?(Kotlin - How to do onCompleteListener to get data From Firestore?)
Kotlin - 如何使用onCompleteListener从Firestore获取数据?(Kotlin - How to do onCompleteListener to get data From Firestore?)
我有问题从Firestore获取数据,在JavaCode中我们可以这样做:
DocumentReference docRef = db.collection("cities").document("SF"); docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); if (document != null) { Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData()); } else { Log.d(TAG, "No such document"); } } else { Log.d(TAG, "get failed with ", task.getException()); } } });
但在Kotlin,当我尝试覆盖onComplete函数时,它不可用。 那么,我怎么能得到“任务”?
I have a problem to Get data From Firestore, in Java code we can do this :
DocumentReference docRef = db.collection("cities").document("SF"); docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); if (document != null) { Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData()); } else { Log.d(TAG, "No such document"); } } else { Log.d(TAG, "get failed with ", task.getException()); } } });
but in Kotlin, when I try to override the
onComplete
function, it's unavailable. so, how I can get the "task"?
原文:https://stackoverflow.com/questions/47214368
更新时间:2024-02-02 18:02
最满意答案
其中一个网卡出现故障。 我交换了网卡,它工作正常。 不知道为什么它以这种方式出现,但至少我找到了解决方案。
One of the NICs was faulty. I swapped the NIC and it worked fine. Not sure why it presented itself in this one way but at least I found the solution.
相关问答
更多-
在您的WSServerProtocol类中,在onMessage线程中: def onMessage(self, msg, binary): self.sendMessage(msg) in your WSServerProtocol class, in the onMessage thread : def onMessage(self, msg, binary): self.sendMessage(msg)
-
在代理中中继分块响应(Relay chunked response in Proxy)[2022-05-22]
FiddlerCore是HTTP / 1.1协议的完整实现,直接在TCP / IP套接字上编写。 因此,它不会受到更高级别WebRequest类固有的限制(代价是我必须自己完全实现协议)。 I actually decided to chunk the data again each time I read in to the buffer from the responsestream (only if the response header is indicating a chunked respons ... -
其中一个网卡出现故障。 我交换了网卡,它工作正常。 不知道为什么它以这种方式出现,但至少我找到了解决方案。 One of the NICs was faulty. I swapped the NIC and it worked fine. Not sure why it presented itself in this one way but at least I found the solution.
-
WCF Http到Tcp代理(WCF Http to Tcp Proxy)[2022-01-02]
在目前的WCF 3.5中,你必须自己做这件事 - 参见优秀的两部分文章 构建WCF路由器,第1部分 构建一个WCF路由器,第2部分 Michele Leroux Bustamante。 随着WCF 4--与.NET 4一起发布,大概在2010年3月 - 事情会变得更容易,因为WCF 4已经包含了一个基础的“RoutingService”类 - 请参阅Ron Jacobs关于此主题的Endpoint.TV视频采访 。 渣子 In current WCF 3.5, you have to do this you ... -
当我们知道B准备好接收数据时,是否可以只读取套接字A? 当然:在套接字A和B上使用select.select (如果它返回说只有其中一个已准备就绪,在另一个套接字上使用它),并且只有当你知道它们都准备就绪时才从A读取并写入B. 例如: import select def fromAtoB(A, B): r, w = select.select([A], [B], []) if not r: select.select([A], [], []) elif not w: select. ...
-
尝试将--skip-ssl指定为mysql客户端的选项。 我们正在修复此问题,并且应该在不久的将来推出。 发生这种情况的原因是我们拒绝通过请求MySQL SSL的代理连接。 代理和Cloud SQL之间的连接已经通过SSL完成,因此不需要在MySQL级别使用SSL。 Try specifying --skip-ssl as an option to your mysql client. We have a fix for this in progress and should be rolled out i ...
-
tcp-client-server-multiplex显示了一种异步代理请求/回复方案的机制; 您需要数据中的某些内容才能将回复与请求相关联。 它使用聚合器来做到这一点。 使用自述文件中引用的更简单的tcp-client-server示例,使用网关并且框架可以处理相关性(但它不会处理高容量,除非您在出站端使用CachingClientConnectionFactory (这实际上是您的如果您无法添加一些与回复相关的数据,则只有选项。 如果您只谈论单向消息传递,那么显然不需要关联(并且您在第一个示例中不需要聚 ...
-
使用Async套接字为TCP代理服务器实现线程(Implementing threading for a TCP proxy server using Async sockets)[2022-03-23]
这听起来像是你想要穿线的缘故。 通过添加额外的线程究竟会解决什么问题? 鉴于异步模型回调到ThreadPool,你已经免费获得“线程化”。 你为什么想要更多? 您可以愉快地在读取操作的异步回调中从一个流复制到另一个流。 如果你也使用async进行编写,那么它不会对ThreadPool造成任何重大负担,而IMO的工作最好留在那里。 您是否考虑过使用async / await? 如果它是一个选项,那么它将使您的代码在大脑上的几度嵌套更轻。 It sounds like you want threading fo ... -
编辑 :该错误已在aiosmtpd 1.0b1中修复,因此升级应解决此问题。 在aiosmtpd 1.0a4中,Proxy.handle_DATA中的未捕获异常(使用data作为str而不是字节)会导致asyncio任务停止,但异常永远不会传播。 如果你升级到1.0a5,你将得到正确打印的异常:“错误:(TypeError)不能在字节类对象上使用字符串模式”。 问题是,从1.0a5开始,aiosmtpd中的Proxy设计用于在aiosmtpd.smtp.SMTP对象上设置decode_data=True的C ...
-
Python文档中的示例提供了实现客户端 - 服务器系统的基本背景。 但是,在两者之间添加代理需要对示例代码进行一些应用。 客户端 - 代理 - 服务器系统的骨架模型 客户 客户应该做以下事情: 阅读将要发送的文件 open() , fp.read()等 创建套接字并建立与代理的TCP连接 socket.socket() , proxysock.connect()与SOCK_STREAM 将存储在步骤1中的变量中的文件数据发送到代理 proxysock.sendall() 等待答案 proxysock.re ...