TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using core.async and transducers to upload files from the browser to S3

14 点作者 mklappstuhl超过 10 年前

2 条评论

danneu超过 10 年前
<p><pre><code> &gt; I still need to look into some things like &gt; how to properly shut down the `go` blocks. </code></pre> I have limited core.async experience, but one simple solution would be to replace `(go (while true ... (&lt;! report-chan)))` with a `core.async&#x2F;go-loop` that `alts!` from `[report-chan, (core.async&#x2F;timeout 10000)]`. If the value comes from `report-chan`, then recur. If the value comes from the timeout channel (10 seconds of no activity) then don&#x27;t thus ending the go block execution.<p>For more control, you can pass a poison channel in from the outside. In the go-loop, `alts!` from `[report-chan, poison-chan, (timeout 10000)]`. Like the timeout channel, don&#x27;t recur if the value comes from poison-chan. And that&#x27;s a chan that your exterior code will have access to.
freshhawk超过 10 年前
I&#x27;m pretty sure that the alts! block is absolutely necessary otherwise you will deadlock after 10 files (your channel buffer size) because nothing else is taking from upload-chan or signing-chan.<p>Wouldn&#x27;t a pipeline be a better solution to this? Taking and throwing away the values from a channel just to trigger a transducer that puts the value in another channel as a side effect is a strange way to do things.<p>Also a simple println test will show that the transducer function <i>is</i> triggered when you put on the channel rather than when you take.