async

vue中axios进行同步请求(async + await)

风流意气都作罢 提交于 2020-01-22 12:28:44
当需要异步请求的返回值时,可以在成功回调函数中进行操作;但是必须要同步执行的时候可以用 async + await 进行阻塞。 1.await后面接一个会return new promise的函数并执行它 2.await只能放在async函数里 //示例1 async function fnName ( ) { const response = await new Promise ( resolve => { setTimeout ( ( ) => { resolve ( "async await test..." ) ; } , 1000 ) ; } ) ; console . log ( response ) ; } fnName ( ) ; //async await test... //自己项目中写的 async userTestRegister ( ) { let data = { token : this . token , username : this . username , } ; let res = await tenant_userTestRegister ( data ) ; //我这里tenant_userTestRegister是封装的请求函数;res为返回的数据; ... 其他操作 } , 来源: CSDN 作者: lifangfang0607 链接

tree

狂风中的少年 提交于 2020-01-21 16:16:35
< el-tree :props = "areaSelectProps" :load = "loadNode" :expand-on-click-node = "false" lazy > < /tree > // 区域树形图 areaSelectProps: { value: 'baseAreaId' , label: 'baseAreaName' , children: 'children' , isLeaf: 'leaf' , } , // 加载下级区域 async loadNode ( node, resolve ) { let baseAreaId = '' ; if ( node.data ) { baseAreaId = node.data.baseAreaId } const areaList = await getExceptionList ( baseAreaId ) ; areaList.map ( v = > { if ( v.childCnt > 0 ) { v.leaf = false } else { v.leaf = true } v.children = [ ] return v } ) resolve ( areaList ) } , 来源: CSDN 作者: 粥萌_ 链接: https://blog.csdn.net/weixin

分享自己写的基于Dapper的轻量级ORM框架~

拥有回忆 提交于 2020-01-21 05:49:57
1、说明 本项目是一个使用.NET Standard 2.0开发的,基于 Dapper 的轻量级 ORM 框架,包含基本的CRUD以及根据表达式进行一些操作的方法,目前只针对单表,不包含多表连接操作。 github: https://github.com/iamoldli/NetSql 2、使用方法 2.2、安装 Install-Package NetSql 2.2、创建实体 创建 Article 实体类,继承 EntityBase public class Article : EntityBase { [Column("Title")] public string Title1 { get; set; } public string Summary { get; set; } public string Body { get; set; } public Category Category { get; set; } public int ReadCount { get; set; } public bool IsDeleted { get; set; } public DateTime CreatedTime { get; set; } } public enum Category { Blog, Movie } EntityBase 是一个定义好的实体基类

学习笔记|async 函数

旧城冷巷雨未停 提交于 2020-01-20 17:02:56
1.含义 ES2017 标准引入了 async 函数,使得异步操作变得更加方便。 async 函数是什么?一句话,它就是 Generator 函数的语法糖。 前文有一个 Generator 函数,依次读取两个文件。 const fs = require('fs'); const readFile = function (fileName) { return new Promise(function (resolve, reject) { fs.readFile(fileName, function(error, data) { if (error) return reject(error); resolve(data); }); }); }; const gen = function* () { const f1 = yield readFile('/etc/fstab'); const f2 = yield readFile('/etc/shells'); console.log(f1.toString()); console.log(f2.toString()); }; 上面代码的函数gen可以写成async函数,就是下面这样。 const asyncReadFile = async function () { const f1 = await readFile('/etc

【nodeJS爬虫】前端爬虫系列

白昼怎懂夜的黑 提交于 2020-01-20 05:36:32
本文转自 http://www.cnblogs.com/coco1s/p/4954063.html 写这篇 blog 其实一开始我是拒绝的,因为爬虫爬的就是cnblog博客园。搞不好编辑看到了就把我的账号给封了:)。 言归正传,前端同学可能向来对爬虫不是很感冒,觉得爬虫需要用偏后端的语言,诸如 php , python 等。当然这是在 nodejs 前了,nodejs 的出现,使得 Javascript 也可以用来写爬虫了。由于 nodejs 强大的异步特性,让我们可以轻松以异步高并发去爬取网站,当然这里的轻松指的是 cpu 的开销。 要读懂本文,其实只需要有 能看懂 Javascript 及 JQuery 简单的nodejs基础 http 网络抓包 和 URL 基础 本文较长且图多,但如果能耐下心读完本文,你会发现,简单的一个爬虫实现并不难,并且能从中学到很多东西。 本文中的完整的爬虫代码,在 我的github上可以下载 。主要的逻辑代码在 server.js 中,建议边对照代码边往下看。 在详细说爬虫前,先来简单看看要达成的最终目标,入口为 http://www.cnblogs.com/ ,博客园文章列表页每页有20篇文章,最多可以翻到200页。我这个爬虫要做的就是异步并发去爬取这4000篇文章的具体内容,拿到一些我们想要的关键数据。 爬虫流程 看到了最终结果

使用@Async注解,执行异步程序

寵の児 提交于 2020-01-19 19:53:35
直接贴代码 自定义线程池 package com.xh.lawsuit.rest.modular.example; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.Executor; @Configuration public class GlobalThreadPool { @Bean public Executor taskExecutor() { int cpuCount = Runtime.getRuntime().availableProcessors() ; int coreThreadSize = cpuCount << 1; int maxThreadSize = cpuCount << 4; ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize

Vue.实战项目——Day(3)

不羁岁月 提交于 2020-01-19 03:27:02
今日目标 1.修改用户,删除用户 2.推送代码到码云 3.权限列表 4.角色列表 5.分配角色 1.修改用户信息 A.为用户列表中的修改按钮绑定点击事件 B.在页面中添加修改用户对话框,并修改对话框的属性 C.根据id查询需要修改的用户数据 //展示编辑用户的对话框 async showEditDialog(id) { //发送请求根据id获取用户信息 const { data: res } = await this.$http.get('users/' + id) //判断如果添加失败,就做提示 if (res.meta.status !== 200) return this.$message.error('获取用户信息失败') //将获取到的数据保存到数据editForm中 this.editForm = res.data //显示弹出窗 this.editDialogVisible = true } D.在弹出窗中添加修改用户信息的表单并做响应的数据绑定以及数据验证 <!-- 对话框主体区域 --> <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="70px"> <el-form-item label="用户名"> <el-input v-model=

深入理解协程(四):async/await异步爬虫实战

邮差的信 提交于 2020-01-18 12:18:09
本文目录: 同步方式爬取博客标题 async/await异步爬取博客标题 本片为深入理解协程系列文章的 补充 。 你将会在从本文中了解到: async/await 如何运用的实际的爬虫中。 案例 从CSDN上批量爬取指定文章的标题。文章列表如下: urls = [ 'https://blog.csdn.net/Jmilk/article/details/103218919', 'https://blog.csdn.net/stven_king/article/details/103256724', 'https://blog.csdn.net/csdnnews/article/details/103154693', 'https://blog.csdn.net/dg_lee/article/details/103951021', 'https://blog.csdn.net/m0_37907797/article/details/103272967', 'https://blog.csdn.net/zzq900503/article/details/49618605', 'https://blog.csdn.net/weixin_44339238/article/details/103977138', 'https://blog.csdn.net

async & await

ぐ巨炮叔叔 提交于 2020-01-18 04:57:26
【 await 】   The await operator is used to wait for a Promise . It can only be used inside an async function .   Returns the resolved value of the promise, or the value itself if it's not a Promise .   The await expression causes async function execution to pause, to wait for the Promise 's resolution, and to resume the async function execution when the value is resolved. It then returns the resolved value. If the value is not a Promise , it's converted to a resolved Promise .   If the Promise is rejected, the await expression throws the rejected value. async function f3() { try { var z = await

javascript中优雅的处理async和await异常

夙愿已清 提交于 2020-01-18 04:54:44
let handler = async function(needErr) { return new Promise((resolve, reject) => { if (needErr) { reject(new Error('执行失败,给出错误')) } else { resolve('执行成功,没有报错') } }) } let run = async function() { let result = await handler(false).catch(); console.log(result); result = await handler(true).catch(); console.log(result); } run(); 输出: 执行成功,没有报错 (node:3428) UnhandledPromiseRejectionWarning: Error: 执行失败,给出错误 async函数总是返回promise实例 无论是return了Promise, 还是内部调用了await, 就算什么也没做,它也返回promise; 一个函数,只要被标记了async,那么它就返回Promise对象 所以上面的handler函数返回的是一个promise实例 如果一个 async 函数返回的是一个 reject 的 Promise,那么这个 Promise 依然会继续被