问题标签 [fluture]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - 将 Fluture 与 Ramda 一起使用
我用 Bluebird 做异步的东西,但现在必须做很多空/空/错误检查,我不想走通常的 if Else 路线。我正在考虑使用单子,但还没有完全理解它。
此外,我希望它与 ramda 很好地配合,pipe / compose
因为我的大多数其他代码都巧妙地封装在功能管道中。根据许多 讨论, monadic Futures(似乎推荐 Fluture)优于 Promises,并且在未来的版本中可能会删除对 pipeP 和 composeP 的支持。
Fluture 似乎是一个不错的选择,因为它应该与符合幻想世界规范的库(如 ramda)配合得很好。
但是,我完全不知道如何实现将 Ramda 的管道与 Fluture 集成的东西。我需要一些示例代码的帮助。
例如:
我有一个返回对象数组的数据库调用。数组可能有值、为空或未定义。我有一个功能管道,可以转换数据并将其返回到前端。
示例承诺代码:
有人可以就继续进行的好方法给出一些指示。
javascript - 有人可以告诉我 Task 和 Future 并发操作有什么区别吗?因为界面看起来一样
正如您在此处看到的,两者都接受函数计算,惰性且都是可组合的。那么这些类型之间的主要区别是什么。
javascript - 将 Fluture Future 转换为民间故事结果
我有以下示例代码来获取 uuid:
结果不是可映射类型,并在我调用时引发错误result.map
:
tdd - 如何存根 Fluture?
背景
我正在尝试使用 Flutures 和 Sanctuary 将旧 Promises 中的代码片段转换为某些东西:
https://codesandbox.io/embed/q3z3p17rpj?codemirror=1
问题
现在,通常,使用 Promises,我可以使用像sinonjs这样的库来存根 Promise,即伪造它们的结果、强制解决、拒绝等。
这是基本的,因为它有助于测试多个分支方向并确保一切正常。
然而,对于 Flutures,情况就不同了。不能简单地存根 Fluture,我也没有找到任何可以提供帮助的 sinon 式库。
问题
- 你如何存根 Flutures ?
- 对使用 Flutures/Sanctuary 进行 TDD 有什么具体建议吗?
javascript - Fluture bimap 和 fold,有什么区别,什么时候应该使用它们?
背景
我正在使用Fluture来抽象 Futures。
假设我有一个发出 GET 请求的函数。这个函数可以成功也可以失败。
发出请求时,如果成功,则打印一条消息,如果失败,则记录错误并执行命令。
研究
我一直在阅读 API,我发现bimap
两者fold
都将函数应用于成功和错误:
bimap:将左函数映射到拒绝值,或将右函数映射到分辨率值,具体取决于存在的情况。
fold:将左函数应用于拒绝值,或将右函数应用于分辨率值,具体取决于存在的情况,并使用结果进行解析。
问题
如果你有敏锐的眼光,你就会知道我的例子行不通。我需要使用bimap
,但我不明白为什么。
问题
- 我应该什么时候使用
bimap
,什么时候应该使用fold
? - 它们之间的主要区别是什么?
logging - How to log properly in Sanctuary / Fluture?
Background
I have a function, called logInfoAsync
. Let's consider this function sends some information to a log server over the network. For the purposes of this question let's assume the function is implemented as follows:
Usage:
Problem
So far so good. We have a standard logger that sometimes works and sometimes it angers the Gods.
Now, let's assume that we have a series sequential async
computations:
In this example, what happens if the logger angers the Gods? Well, We fail to save the data! Maybe the request went fine, and maybe the data was valid, but because the logger failed, we got screwed!
Research
Now, a possible solution to this would be to use Fluture.bimap
after every log.
This would be horrible.
I don't want my logs to be more invasive than they already are and I most definitely do not what to litter my code with Promise styled try/catch
s.
Unfortunately for me, this is the only thing I can think off ... I think that the best option would be a backup logger, for example, console.error
that is used should the myLogF
fail, but I ideally I would want this to be invisible.
The application should not be aware it is being logged at all!
Questions
So, given this snippet, I have the following questions:
- How would you keep the chain going if a log fails?
- How would you make log failure and recovery invisible to the application ( without littering it with the equivalent of (
try/catch
)? - What is the most commonly used pattern for logs?
fetch - 在`fetch`上使用Fluture`encaseP`时出现UnhandledPromiseRejectionWarning
我刚刚开始使用Flutures,我正在尝试获取一些远程数据以使用 d3 进行可视化。
我创建了一个函数,它接受一个 DOM 选择器(例如#my-chart
)和一个 url(例如https://example.com/data.json
)。
如果在获取数据时发生错误,我有一个显示错误消息的一元函数。如果一切顺利,我有一个绘制可视化的一元函数。为了简单起见,我们假设这些函数只是console.error
和console.log
。
显然我在包装fetch
未来时遗漏了一些东西,因为我收到了这个警告:
如果我不得不使用async/await
我会写这样的东西,这不会给我任何警告。
javascript - 将 Fluture 与 AWS 服务结合使用
我正在使用 Fluture 来处理来自 AWS 服务请求的响应。
我使用回调或围绕回调的 Promise 获得预期的响应。当我尝试使用长笛时,看起来我正在反刍请求。一定是个笨蛋……(再次)
预期结果:{ TextDetections: [ { DetectedText: 'text1', Type: 'LINE', Id: 0, Confidence: 98.7948989868164, Geometry: [Object] }, { DetectedText: 'text2',...
实际结果:c5GeDWkmkn3ZpFJK/UszSxBOCN2AR7Gs0uqtHlSDuGHX+EnuakC43xxqN6ABWY/e+lRiOaNrg+UWKqGAHfii0bXZv...
javascript - 在 Sanctuary 管道中间执行 Fluture 任务
我有这样的管道:
此管道中间有 2 个异步函数。我想await
forcopyImageToPublicPath
然后await
forcopyFileToPath
然后继续正常流程
经过一番搜索,我发现有Future.tryP
功能可以做async
,但我如何Fluture
在这个管道中间使用?
javascript - 使用 Sancuary Either 执行 Fluture 任务
我有这样的管道
我想在asyncFn
. 问题是当我有Right
输入时,我可以再分叉它。
当我登录时,pipeResult
我看到:
我怎样才能做到这一点?