繁体   English   中英

使用 Google Cloud Functions 时刷新分块传输?

[英]Flushing chunked transfer when using Google Cloud Functions?

exports.cloudFunctionEntryPoint = async (req, res) => {
    setTimeout(()=>{
        res.write("1\n");
    }, 1000)
    setTimeout(()=>{
        res.write("2\n");
    }, 2000)
    setTimeout(()=>{
        res.write("3\n");
    }, 3000)
    setTimeout(()=>{
        res.write("4\n");
    }, 4000)
    setTimeout(()=>{
        res.write("5\n");
        res.end();
    }, 5000)
}

使用本地 expressjs 服务器时,服务器会在每次res.write时立即刷新,因此我可以每秒获取数字。

但是在 GCF 上,只有在res.end()时才会刷新数据,所以我只能在第 5 秒将所有数字放在一起。

有没有办法让 GCF 在每个res.write上刷新?

这是不可能的。 Cloud Functions 在发送到客户端之前会缓冲所有 output,最大为 10MB。

也可以看看:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM