- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我突然想到流式传输字符串是有意义的,每个字符串代表来自数据库查询的一个元素,而不是在过程结束时返回它们的整个列表,这可能会在浏览器上更早地获得第一个结果.所以我尝试用 Redstone
来实现它使用Shelf
.这是我的基本测试
@app.Route ('/testStream')
testSream ()
{
StreamController<String> controller = new StreamController<String> ();
() async
{
var initialTime = new DateTime.now();
await new Future.delayed (new Duration (seconds: 1));
controller.add("hello\n");
await new Future.delayed (new Duration (seconds: 10));
controller.add("chao\n");
var finalTime = new DateTime.now().difference(initialTime);
controller.add(finalTime.toString());
controller.close();
}();
Stream<List<int>> intStream = controller.stream.map((s) => s.codeUnits);
return new shelf.Response.ok (intStream);
}
只是在某些情况下,Linked-in 的人使用他们从 Facebook 获得的模式中的“文本流”来快速呈现页面的一部分并插入一些后者(如果可用),他们在 Playframework (Scala) 中实现了这一点他们在哪里使用 Enumerables
这看起来就像 Dart 流一样。你可以在 this video 中看到它.
我的代码的问题在于,虽然我希望它显示 "hello"
1 秒 后,"chao"
10 秒 后。我得到的是 11 秒 的等待,然后是完整的文本。如您所见,我正在回复 Shelf.Response
用Stream<List<int>>
每个List<int>
只是将原始流中的字符串转换为字节。
这是 Shelf 问题/功能,还是 Redstone 搞乱了响应并将其转换为 future ?有什么解决办法吗?
编辑
我想得到什么
1 秒内没有任何内容。
1秒后
hello
11 秒后
hello
chao
0:00:11.009000
我真正得到了什么
1 秒内没有任何内容。
11 秒后
hello
chao
0:00:11.009000
最佳答案
对于那些后来到这里的人:
正如@Pacane 在问题评论中所建议的,他发布的链接 ( https://github.com/dart-lang/shelf/issues/54 ) 确实包含 Andersmholmgren 的评论,该评论适用于该问题:
return new Response.ok(counterStream, context: {"shelf.io.buffer_output": false});
将“shelf.io.buffer_output”选项设置为 false 会禁用 Shelf 的输出缓冲区,并使添加到响应流的字节直接通过网络发送到客户端。
关于dart - 使用 Redstone/Shelf 在 Dart 中流式传输文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29238873/
我有一个用Shelf和Rpc api编写的dart Web服务应用程序。 我需要在我的api方法中检查客户端Ip,但是我不知道怎么做。 上下文方法不包含HttpRequest .contentInfo
我想将一些更改从我的Mercurial架子复制到我的工作目录中,而在架子上保留一个不变的副本。 Git可以让我使用git stash apply做到这一点,但是我找不到让TortoiseHg做到这一点
我认为最好的解释方式是举个例子: >>> class Person: ... def __init__(self, brother=None): ... self.brothe
我有一个很大的字典 100 000 个键和大型 numpy 数组作为值。我想将其另存为文件以便更快加载。 我尝试将其转储为泡菜,但内存不足。然后尝试了 json.dump 但不支持 Numpy 数组作
我正在使用架子类来完成我的工作。但我不知道为什么它不起作用。这就是我正在做的事情: import shelve file = shelve.open('data.db') shelf = shelve
我突然想到流式传输字符串是有意义的,每个字符串代表来自数据库查询的一个元素,而不是在过程结束时返回它们的整个列表,这可能会在浏览器上更早地获得第一个结果.所以我尝试用 Redstone 来实现它使用S
我正在使用 Dart Shelf 框架构建 API。 Get 工作正常,但我在发布时遇到问题。我无法访问服务器中发布请求的任何正文参数。这是我尝试过的。 // shelf-router router.
我想在我的应用程序中显示一些书籍和杂志封面(类似于 iBooks 中的书架 View )。到目前为止,我已经实现了自己的 UIScrollView,它可以很好地显示封面 - 不幸的是,由于性能问题,我
我有一个库,它发出 Web 请求并将结果传递给回调,如下例所示: someReadyWebSearchThirdPartyLibrary.getSearch(parameters, error, ca
我很想知道是否有人以编程方式在 tvOS 应用程序中成功设置了 Top Shelf 图像?我已经阅读了一些教程(例如 this one),其中详细介绍了以 sectioned 或 inset 样式设置
我创建了一个简单的 AppleTV 项目来按类别显示多个视频,浏览和播放视频工作正常。它已作为使用 TVML 和 TVJS 的客户端-服务器应用程序实现,因此大部分应用程序逻辑都在 Javascrip
我只是按照书中给出的示例来说明 macOS High Sierra 上的 Python shelve 模块。 如下所示,只有两个短字符串的小元组存储在一个 shelf 中。正如您在最后一行中看到的那样
假设有人让我为他们构建一个具有大量自定义功能的 youtube 克隆,以支持他们想做的一大堆古怪的事情。 我如何决定从头开始构建与构建白标产品或开源产品对我来说是否更好? 由于我过去的工作经验,我倾向
我想使用 RPC 库来开发 Dart 服务器端 Restful。在库存储库中,它带来了两个使用示例(https://github.com/dart-lang/rpc-examples/tree/mas
我有一个使用 jest 的项目,我可以用 npm test 运行 jest如果我不设置预设,它就可以工作。 我需要预设@shelf/jest-mongodb ,我得到了这篇文章标题中的错误。 这是我的
我需要在 Shelf 中设置多个“set-cookie” header ,但由于 header 是 Map ,设置第二个替换第一个等等,因为键是唯一的。我如何在 Dart 中解决这个问题? 最佳答案
我正在从事集成测试,因此从数据库获取数据会使测试用例执行速度变慢。尝试使用 jest-mongodb 设置临时数据库。但无法找到在 typescript-nodejs 项目中设置 jest-mongo
这张图片来自this document in Material Designspecification .它的标题是: Flexible toolbar and card toolbar 为什么他们称
我是一名优秀的程序员,十分优秀!