async

小程序中使用async函数 会报 regeneratorRuntime is not defined的问题

匿名 (未验证) 提交于 2019-12-02 23:55:01
async await比Promise更好的解决异步操作问题,但是在小程序中直接使用会出现以下的错误提示 是因为缺少了regeneratorRuntime这个模块,需要从外部引入 1.在新建的文件夹中执行 npm init ,生成package.json文件(一路回车就好) 2.执行 npm install regenerator@0.13.1 3.找到并将node_modules/regenerator-runtime/runtime.js复制到小程序项目中 4.在需要使用到async await的.js文件中引入runtime.js 来源:博客园 作者: M_小黎 链接:https://www.cnblogs.com/mxiaoli/p/11424712.html

测试Promise与Async/await的基本使用

匿名 (未验证) 提交于 2019-12-02 23:55:01
想在项目中用, 发现自己不是很熟 new Promise() 返回了一个状态机 一个完全无法被外界影响的状态机 构造函数, 传入一个函数, 两个参数, 分别是 reslove, reject 表示执行的回调函数, 也就是 .then() , .cache() 函数 达到内部调用外部函数的作用, 行程异步 function init () { var p = new Promise (( resolve , reject ) => { reject ( new Error ( 1 )) }) p . then ( a => { console . log ( a ) }). catch ( b => { console . log ( b ) }) console . log ( p ) } init () 命名不可错误 reject回调函数中, 尽量放入一个 new Error 如果直接在 new Promise() 的构造函数中, throw new Error() 也不会触发程序的停止, 而是被外面的 .cache() 所捕获 如果函数没有进行 .cache() 的话, 会抛出异常 但不会影响其他程序的执行 function init () { var p = new Promise (( resolve , reject ) => { throw new Error ( 1

MongoDB数据库(6)__motor

匿名 (未验证) 提交于 2019-12-02 23:49:02
2019.7.22: motor是异步实现python操作数据库的工具。能减少后端访问数据库的延迟。 Motor 是一个异步实现的 MongoDB 存储库 Motor 与 Pymongo 的配置基本类似。连接对象就由 MongoClient 变为 AsyncIOMotorClient 了。 一、连接 # 普通连接 client = motor.motor_asyncio.AsyncIOMotorClient('mongodb://localhost:27017') # 副本集连接 client = motor.motor_asyncio.AsyncIOMotorClient('mongodb://host1,host2/?replicaSet=my-replicaset-name') # 密码连接 client = motor.motor_asyncio.AsyncIOMotorClient('mongodb://username:password@localhost:27017/dbname') # 获取数据库 db = client.zfdb # db = client['zfdb'] # 获取 collection collection = db.test # collection = db['test'] 二、添加一条记录 async def do_insert():

async异步流程控制神器

匿名 (未验证) 提交于 2019-12-02 23:43:01
async https://www.npmjs.com/package/async Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript . Although originally designed for use with Node.js and installable via npm install async , it can also be used directly in the browser. A ESM version is included in the main async package that should automatically be used with compatible bundlers such as Webpack and Rollup. A pure ESM version of Async is available as async-es . For Documentation, visit https://caolan.github.io/async/ For Async v1.5.x documentation, go HERE API https:/

EF部分字段修改

匿名 (未验证) 提交于 2019-12-02 23:43:01
传入一个实体 student(){id = 1,name = "测试" age = null,sex = null} 下面 是修改的方法 public async Task EditAsync(T model, bool IsSava = true) { _Db.Configuration.ValidateOnSaveEnabled = false; //关闭验证 _Db.Entry(model).State = EntityState.Modified; if (IsSava) { await _Db.SaveChangesAsync(); _Db.Configuration.ValidateOnSaveEnabled = true; } } 看代码吧 public async Task EditAsync(T model, bool IsSava = true) { _Db.Configuration.ValidateOnSaveEnabled = false; _Db.Entry(model).State = EntityState.Modified; foreach (var item in model.GetType().GetProperties()) { if (item.GetValue(model) != null) { _Db.Entry(model)

Fetch使用方法

匿名 (未验证) 提交于 2019-12-02 23:40:02
前言: 什么是fetch?   fetch api是基于promise的设计,它是为了取代传统xhr的不合理的写法而生的。 WHY fetch?   xhr请求写起来非常的混乱,如下所示: var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = 'json'; xhr.onload = function() { console.log(xhr.response); }; xhr.onerror = function() { console.log("Oops, error"); }; xhr.send();      但是使用fetch之后,如下所示: fetch(url).then(function(response) { return response.json(); }).then(function(data) { console.log(data); }).catch(function(e) { console.log("Oops, error"); });   这种链式调用的风格看上去会非常舒服。 fetch(url).then(response => response.json()) .then(data => console.log(data)) .catch(e =>

flutter项目报错Error retrieving device properties for ro.product.cpu.abi

匿名 (未验证) 提交于 2019-12-02 23:38:02
时间:2019.06.10 基本信息: 错误信息: Error retrieving device properties for ro.product.cpu.abi: Launching lib\main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... --------- beginning of system 01-22 22:51:04.010 E/BatteryStatsService( 1698): modem info is invalid: ModemActivityInfo{ mTimestamp=0 mSleepTimeMs=0 mIdleTimeMs=0 mTxTimeMs[]=[0, 0, 0, 0, 0] mRxTimeMs=0 mEnergyUsed=0} Unhandled exception: Exit code -1073740940 from: C:/Development/Android\platform-tools\adb -s emulator-5554 shell -x logcat -v time -t 1 #0 _runWithLoggingSync (package:flutter

async和await

匿名 (未验证) 提交于 2019-12-02 23:34:01
先说一下async的用法,它作为一个关键字放到函数前面,用于表示函数是一个异步函数,因为async就是异步的意思, 异步函数也就意味着该函数的执行不会阻塞后面代码的执行。 写一个async 函数 async function timeout() {   return 'hello world'; } 语法很简单,就是在函数前面加上async 关键字,来表示它是异步的,那怎么调用呢?async 函数也是函数,平时我们怎么使用函数就怎么使用它,直接加括号调用就可以了,为了表示它没有阻塞它后面代码的执行,我们在async 函数调用之后加一句console.log; async function timeout() { return 'hello world' } timeout(); console.log('虽然在后面,但是我先执行'); 原来async 函数返回的是一个promise 对象,如果要获取到promise 返回值,我们应该用then 方法 async function timeout() { return 'hello world' } timeout().then(result => { console.log(result); }) console.log('虽然在后面,但是我先执行'); 这时,你可能注意到控制台中的Promise 有一个resolved

swoole之异步文件IO

匿名 (未验证) 提交于 2019-12-02 23:32:01
一、代码部分 读: <?php /** * 异步文件系统仅限于4.3.0之前的版本 * 读取文件 */ $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'1.txt'; // 最后执行回调函数 // swoole_async_readfile最大可读取4M的文件,受限于SW_AIO_MAX_FILESIZE宏 // 使用 swoole_async_read() $result = swoole_async_readfile($filename, function ($filename, $fileContent) { echo 'filename: '.$filename.PHP_EOL; echo 'content: '.$fileContent.PHP_EOL; }, FILE_APPEND); // 返回bool var_dump($result); // 此处先执行 echo 'start'.PHP_EOL; 写: <?php $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'1.txt'; $content = date('Y-m-d H:i:s'); swoole_async_writefile($filename,$content, function(