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. vue中判断路由变化

    使用from.path和to.path判断路由跳转 在methods里面写函数: 当然,上边函数里边可以做很多事情.

  2. 内核中的宏定义__init、__initdata和__exit、__exitdata

    __init.__initdata和__exit.__exitdata的定义位于<kernel/include/linux/init.h> /* These are for everybo ...

  3. 【2017"百度之星"程序设计大赛 - 初赛(A)】度度熊的01世界

    [链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=775&pid=1006 [题意] 在这里写题意 [题 ...

  4. home-界面返回上一级功能

    1,这个主要是用在actionbar上home键,直接上代码 import android.view.MenuItem; /* Vanzo:zhangshuli on: Mon, 23 Mar 201 ...

  5. 文件上传流式处理commons-fileupload

    1. 从请求中获取MultipartFile @RequestMapping(value="/upload", method=RequestMethod.POST) public ...

  6. 00103_死锁、Lock接口、等待唤醒机制

    1.死锁 (1)同步锁使用的弊端:当线程任务中出现了多个同步(多个锁)时,如果同步中嵌套了其他的同步.这时容易引发一种现象:程序出现无限等待,这种现象我们称为死锁.这种情况能避免就避免掉: synch ...

  7. LeetCode Algorithm 06_ZigZag Conversion

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  8. FZU《C语言程序综合设计》

    一年前的玩意. 老是有人找我要..一年前写得这么搓都不敢拿出来.... 但是好多人要啊.....直接发blog,省得下次还要发压缩文件.. 就不要吐槽我代码烂了,我也觉得很烂,至少现在看来确实很烂.. ...

  9. 异步FIFO设计

    参考http://www.cnblogs.com/BitArt/archive/2013/04/10/3010073.html http://blog.sina.com.cn/s/blog_6d30f ...

  10. 基于StringUtils工具类的常用方法介绍(必看篇)

    前言:工作中看到项目组里的大牛写代码大量的用到了StringUtils工具类来做字符串的操作,便学习整理了一下,方便查阅. isEmpty(String str) 是否为空,空格字符为false is ...