我将概念性地引用“推送”与“轮询”流来帮助描述我的问题的目标是“*创建推送数据流模拟Dart的stdin流的数据流行为*“
“轮询”:在我的previous question中,Menzoni的回答是“轮询”流的一个很好的例子。始终启动流并将数据请求从 Dart控制台应用移至本机扩展。请求已完成,响应将返回给应用程序。根据我的经验,这是典型的Dart流使用。
“ Pushed ”:来自外部源的数据被推送到控制台应用程序。数据来源和传输技术无关紧要,可能是stdin键盘/鼠标事件,PLC中断,数据库异步通知等。
我将使用stdin流来说明这个例子,它是我试图实现的数据流的一个很好的例子。 virtualkeycodes / ints形式的数据到达本机扩展,缓冲,然后需要“ Pushed ”(发送/发布)到Dart应用程序,而不需要对来自数据的任何拉/轮询请求应用程序。这是我试图在我的native-extension的自定义流中实现的目标!
Dart console app伪代码:
Stream<List<int>> virtKeyCodes = NativeCreatePushedStream_Keycodes();
virtKeyCodes.listen(processInts);
void processInts(List<int> kbinput) {
print("processInts: found ${kbinput.length} kbinput chars");
for (int i = 0; i < kbinput.length; i++) {
print("...kbinput:${kbinput[i]}");
}
}
原生扩展伪代码(我猜这里!)
Initial call create persistant stream
Return to console app where it starts to listen
onDataReady somehow post ints to stream
DartVM pushes to console app
感谢您的帮助。
答案 0 :(得分:2)
通过asynchronous native extension
实施“推送”数据流创建了dxConsole“适用于Windows的Dart控制台库”项目,现在托管在Github上。