async 函数 让方法链式调用 新用法
2023-09-11 14:19:39 时间
今天发现个async的新用法,之前都是搭配着 promise 让一步函数变得同步,今天试了一下下面的写法
async function hello(){ return "hello world"; } hello().then(data=>{ console.log(data + "哈哈");//hello world哈哈 return 11; }).then(a=>{ console.log(a);//11 }).then(()=>{ console.log("ssd");//ssd }).then(()=>{ console.log("啦啦啦");//啦啦啦 })
这样就是 换一种写法而已,并处理不了setTimeOut这种异步,不过可以让函数变成链式的,看着还不错,记录下来,万一有使用场景了。。。
如果想处理异步 还是 async配合promise使用吧
相关文章
- memcached优化方法
- Why exceptions in async methods are “dangerous” in C# 调用async方法,不进行await的时候,会丢失异常 exception disappear in async method
- python-matplotlib绘图 -应用subplots_adjust()方法解决图表与画布的间距问题
- error: Microsoft Visual C++ 14.0 is required问题最佳解决方法pip安装python包报错
- 零基础小白如何学Python?这些方法你需要了解!
- 将ndarray对象的数据按索引矩阵进行选取的几种方法
- 《模式识别》学习笔记(二十二)概率的窗函数估计方法
- c#双缓冲绘图(不闪烁的几种方法)
- CSS(字体相关知识以及css三种样式表使用方法)
- Optional.ofNullable()方法
- Demystifying Closures, Futures and async-await in Rust–Part 3: Async & Await
- 解决:Vue调试工具vue-devtools安装方法——解决下载速度缓慢,安装报错问题
- Java 方法
- 漫说模板方法模式---学生时代的烦恼