We examine the data structure Task, see some constructors, familiar methods, and finally how it captures side effects through laziness.

We using a 'data.task' library. It is a bit similar to $q library in Angular. Accepts one function, function takes two params, 'reject function' & 'resolve function'.

import Task from 'data.task';

const launchMissiles = () =>
new Task((rej, res) => {
console.log('launch missiles!')
res('missile')
})

Because this is laziness, therefore, we can compose logic based on that:

const app = launchMissiles().map(x => x + '!')
app
.map(x => x + '!')
.fork(e => console.error('err', e),
x => console.log('success', x))

If inside 'lauchMissiles' call 'reject' function, all the map function chaining on app won't be called anymore.

'fork' is the actually function which trigger it works.

-----

import Task from 'data.task';

const launchMissiles = () =>
new Task((rej, res) => {
console.log('launch missiles!')
res('missile')
}) const app = launchMissiles().map(x => x + '!') app
.map(x => x + '!')
.fork(e => console.error('err', e),
x => console.log('success', x)) //launch missiles!
success

[Compose] 10. Capture Side Effects in a Task的更多相关文章

  1. [Functional Programming] Capture Side Effects in a Task / Async

    We examine the data structure Task, see some constructors, familiar methods, and finally how it capt ...

  2. kernel 3.10内核源码分析--hung task机制

    kernel 3.10内核源码分析--hung task机制 一.相关知识: 长期以来,处于D状态(TASK_UNINTERRUPTIBLE状态)的进程 都是让人比较烦恼的问题,处于D状态的进程不能接 ...

  3. Spring task定时任务

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  4. Using the Task Parallel Library (TPL) for Events

    Using the Task Parallel Library (TPL) for Events The parallel tasks library was introduced with the ...

  5. 编写 capture filters

    编写 capture filters 如有转载,请在转载前给我提一些建议.谢谢. 百度查不到资料,为无能的百度搜索增加点营养的料. 读 http://www.n-cg.net/CaptureFilte ...

  6. Mesos源码分析(13): MesosContainerier运行一个Task

    MesosContainerizer的实现在文件src/slave/containerizer/mesos/containerizer.cpp中   Future<bool> MesosC ...

  7. 一次 Spark SQL 性能提升10倍的经历(转载)

    1. 遇到了啥问题 是酱紫的,简单来说:并发执行 spark job 的时候,并发的提速很不明显. 嗯,且听我慢慢道来,啰嗦点说,类似于我们内部有一个系统给分析师用,他们写一些 sql,在我们的 sp ...

  8. linux 3.10 一次softlock排查

    x86架构.一个同事分析的crash,我在他基础上再次协助分析,也没有获得进展,只是记录一下分析过程.记录是指备忘,万一有人解决过,也好给我们点帮助. 有一次软锁,大多数cpu被锁,log中第一个认为 ...

  9. C#中Task的使用简单总结

    Task在并行计算中的作用很凸显,但是他的使用却有点小复杂,下面是任务的一些基本使用说明(转载与总结于多篇文章) 简单点说说吧! 创建 Task 创建Task有两种方式,一种是使用构造函数创建,另一种 ...

随机推荐

  1. 洛谷P1734 最大约数和

    题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入输出格式 输入格式: 输入一个正整数S. 输出格式: 输出最大的约数之和. 输入输出样例 输入样例#1: 复 ...

  2. C++ 复制到粘贴板

    网上好多教程讲如何复制到剪切板,但是有可能复制的是乱码,为了方便,将CString类型的复制到剪切板 CString source;if (OpenClipboard()){//防止非ASCII语言复 ...

  3. SpringMVC 传递相同名称的参数的最佳方法

    华为云4核8G,高性能云服务器,免费试用 >>>   SpringMVC 多个对象的相同字段参数传递解决方案,在SpringMVC中,有时需要传递多个对象(除了Model和web元素 ...

  4. HDU——T 3579 Hello Kiki

    http://acm.hdu.edu.cn/showproblem.php?pid=3579 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  5. nagios 安装配置(包含nrpe端)全 (一)

    一.nagios安装: 1.安装下面命令: 这是本人监控服务时自己定义插件所用到的几个系统命令.可不安装. (1)iostat:监控磁盘IO信息: apt-getinstall sysstat (2) ...

  6. Python的数组合并

    https://blog.csdn.net/hustqb/article/details/78090365 TypeError: can only concatenate list (not &quo ...

  7. 修改shm,oracle11g需要扩大共享内存

    作者:david_zhang@sh [转载时请以超链接形式标明文章] 链接:http://www.cnblogs.com/david-zhang-index/archive/2012/04/26/24 ...

  8. cocos2d-x中六种持续性动作

    持续性动作: (一) 位置变化动作 Move by to Jump by to (二) 属性变化动作 Scale by to Rotate by to Fade in out to Tint to b ...

  9. 【软件project】 文档 - 银行业务管理 - 需求分析

    ---------------------------------------------------------------------------------------------------- ...

  10. JPA学习笔记(11)——使用二级缓存

    一级缓存 查询两次id为1的user User user1 = entityManager.find(User.class, 1); User user2 = entityManager.find(U ...