nodejs when 核心部分使用
来源:互联网 发布:plc与伺服电机编程 编辑:程序博客网 时间:2024/05/22 08:07
// 核心部分CORE
const when = require('when');
// 1.使用when直接构造一个promise
const test1 = when(1);
test1.then(d => {
console.log('1 == ', d);
});
// 2.when构造的promise成功时自动调用函数
const test2 = when(2, console.info);
test2.then(d => {
console.log('2 == ', d);
})
// 3.when是以es的promise包裹的, 你可以通过try在非es5环境下使用
const test3 = when.try(JSON.parse,
new Promise((res, rej) => {
setTimeout(() => res('{ "a": 3 }'), 3000);
})
);
test3.then(d => {
console.log('3 == ', d.a);
})
// 4.lift 其实lift在函数编程中出现得比较频繁, A => B <=> A => f(B) [不知道有没有记错,哈哈]
const fn = nu => nu * nu;
const liftFN = when.lift(fn);
liftFN(4).then(d => {
console.log('4 == ', d);
})
// 5.join 类似Promise.all, 不过多解析
// 6.when.promise(function(resolve, reject, notify) {}) //这里也不过多解析 notify是不赞成使用的
// 7.isPromiseLike 判断是否支持then
const when = require('when');
// 1.使用when直接构造一个promise
const test1 = when(1);
test1.then(d => {
console.log('1 == ', d);
});
// 2.when构造的promise成功时自动调用函数
const test2 = when(2, console.info);
test2.then(d => {
console.log('2 == ', d);
})
// 3.when是以es的promise包裹的, 你可以通过try在非es5环境下使用
const test3 = when.try(JSON.parse,
new Promise((res, rej) => {
setTimeout(() => res('{ "a": 3 }'), 3000);
})
);
test3.then(d => {
console.log('3 == ', d.a);
})
// 4.lift 其实lift在函数编程中出现得比较频繁, A => B <=> A => f(B) [不知道有没有记错,哈哈]
const fn = nu => nu * nu;
const liftFN = when.lift(fn);
liftFN(4).then(d => {
console.log('4 == ', d);
})
// 5.join 类似Promise.all, 不过多解析
// 6.when.promise(function(resolve, reject, notify) {}) //这里也不过多解析 notify是不赞成使用的
// 7.isPromiseLike 判断是否支持then
0 0
- nodejs when 核心部分使用
- Nodejs-核心模块
- Nodejs核心模块 PART1
- Nodejs核心模块 PART2
- Nodejs核心模块
- NodeJs的核心模块
- Nodejs中when库的实例介绍
- case when ...when...when...when..else.. end 使用情况
- nodejs的一些核心概念
- nodejs常用核心模块介绍
- javascript核心部分
- PuzzleGame部分核心算法
- 互联网的核心部分
- JAVASE部分核心知识
- nodejs使用
- nodejs使用
- 【NodeJS】使用forever管理nodejs
- 【NodeJs】NodeJs中使用highstock
- SOAP 简单对象访问协议
- 每天一个linux指令——chgrp
- dentry与inode有什么联系和区别
- jQuery表单对象属性过滤器
- DragTopLayout中TopView下拉缩回问题
- nodejs when 核心部分使用
- 将图片从网站上下载到本地来
- TextView ClickableSpan 事件分发的两个坑
- jstl 表达式 截取字符串
- android 自定义主题样式
- Android入门级之EditText的使用
- 如何在现有的硬件条件下,提升HTC Vive的头显的画质
- zookeeper 常用命令
- 用nginx-gridFS读取MongoDB的图片