当前位置: 首页 > news >正文

怎么安装下载的字体到wordpress页面seo优化

怎么安装下载的字体到wordpress,页面seo优化,网页游戏开服表青云志,网站换空间上怎么办如何实现异步并发限制 文章目录 如何实现异步并发限制方法1注意点 方法2题目要求实现方法注意点 之前一直没有系统的去总结异步并发限制的实现思路,今天就来做个总结吧 方法1 只有一个变量 pool:代表正在执行中的任务中的集合 function sleep(name, t…

如何实现异步并发限制

文章目录

  • 如何实现异步并发限制
    • 方法1
      • 注意点
    • 方法2
      • 题目要求
      • 实现方法
      • 注意点

之前一直没有系统的去总结异步并发限制的实现思路,今天就来做个总结吧

方法1

只有一个变量
pool:代表正在执行中的任务中的集合

function sleep(name, timeOut) {return new Promise(resolve => {console.log(`${name}开始了`);setTimeout(() => {console.log(`${name}结束了`);resolve();}, timeOut);})}const tasks = [() => sleep(1, 1000),() => sleep(2, 2000),() => sleep(3, 3000),() => sleep(5, 6000),() => sleep(8, 8000),];async function parallelLimit(tasks, limit = 2) {// 正在执行中的任务的集合const pool = new Set();for (const task of tasks) {const promise = task();pool.add(promise);promise.then(() => pool.delete(promise));if (pool.size >= limit) {await Promise.race(pool);}}return Promise.all(pool);}parallelLimit(tasks).then(() => {console.log('任务已全部执行');})

注意点

  1. 此时的 pool 代表的是:正在执行中的任务中的集合
  2. 使用 Promise.race 这种方式不能保证执行顺序,若要求要按顺序执行,请看第二种方法

方法2

题目要求

要求实现 Scheduler 函数,完成异步并发限制数为2的功能,且需要保证执行顺序

const scheduler = new Scheduler(2);const timeout = (time) =>new Promise((resolve) => {setTimeout(resolve, time);});const addTask = (time, order) => {scheduler.add(() => timeout(time).then(() => console.log(order)))
}addTask(1000, '1')
addTask(500, '2')
addTask(300, '3')
addTask(400, '4')// 500ms时,2完成,输出2
// 800ms时,3完成,输出3
// 1000ms时,1完成,输出1
// 1200ms时,4完成,输出4

实现方法

function Scheduler(limit) {// 模拟队列,保存所有任务this.pool = [];// 当前正在执行任务的数目this.count = 0;this.add = function (fn) {this.pool.push(fn);this.run();}this.run = function () {if (this.pool.length && this.count < limit) {const task = this.pool.shift(); // 保证执行顺序this.count++;task().then(() => {this.count--;this.run();})}}
}const scheduler = new Scheduler(2);const timeout = (time) =>new Promise((resolve) => {setTimeout(resolve, time);});const addTask = (time, order) => {scheduler.add(() => timeout(time).then(() => console.log(order)))
}addTask(1000, '1')
addTask(500, '2')
addTask(300, '3')
addTask(400, '4')// 500ms时,2完成,输出2
// 800ms时,3完成,输出3
// 1000ms时,1完成,输出1
// 1200ms时,4完成,输出4

注意点

  1. pool 代表保存所有任务的数组
  2. count 代表当前正在执行任务的数目
  3. 保证顺序:需要从数组中顺序取出并执行

两个方法各变量代表的含义不同,实现的思路也就不同,要好好区分两种方法的思想,不然会混淆(像我一样☁️☁️☁️)


道阻且长,面试加油,边复习边查漏补缺吧!!!

passion!!!


文章转载自:
http://dinncoballon.ssfq.cn
http://dinncosystem.ssfq.cn
http://dinncowhore.ssfq.cn
http://dinnconeoclassic.ssfq.cn
http://dinncochangeabout.ssfq.cn
http://dinncobanister.ssfq.cn
http://dinncoextragovernmental.ssfq.cn
http://dinncoencampment.ssfq.cn
http://dinncoflipping.ssfq.cn
http://dinncolimuloid.ssfq.cn
http://dinncooverwatch.ssfq.cn
http://dinncocrotaline.ssfq.cn
http://dinncoelectrotonus.ssfq.cn
http://dinncoprecaution.ssfq.cn
http://dinncodekko.ssfq.cn
http://dinncosouther.ssfq.cn
http://dinncosoniferous.ssfq.cn
http://dinncocorsetting.ssfq.cn
http://dinncodisneyland.ssfq.cn
http://dinnconeuromast.ssfq.cn
http://dinncocrossbreed.ssfq.cn
http://dinncojingoish.ssfq.cn
http://dinncoeverywhither.ssfq.cn
http://dinncoureotelic.ssfq.cn
http://dinncovalid.ssfq.cn
http://dinncoantrim.ssfq.cn
http://dinncobullionism.ssfq.cn
http://dinncoorthogonalize.ssfq.cn
http://dinncohandle.ssfq.cn
http://dinncostylebook.ssfq.cn
http://dinncoeverywhen.ssfq.cn
http://dinncocana.ssfq.cn
http://dinncoinfimum.ssfq.cn
http://dinncolarine.ssfq.cn
http://dinncopreatmospheric.ssfq.cn
http://dinncokinephoto.ssfq.cn
http://dinncobaccate.ssfq.cn
http://dinncodialectology.ssfq.cn
http://dinncomoorland.ssfq.cn
http://dinncolockdown.ssfq.cn
http://dinncoinvaluable.ssfq.cn
http://dinncofenestrated.ssfq.cn
http://dinncohorsemanship.ssfq.cn
http://dinncodeadlight.ssfq.cn
http://dinncobabirussa.ssfq.cn
http://dinncoinstancy.ssfq.cn
http://dinncocountrymen.ssfq.cn
http://dinncocardiotachometer.ssfq.cn
http://dinncounderdogger.ssfq.cn
http://dinncosnowblink.ssfq.cn
http://dinncojaywalking.ssfq.cn
http://dinncoharmonics.ssfq.cn
http://dinncosacrilegiously.ssfq.cn
http://dinncoprocurance.ssfq.cn
http://dinncoacequia.ssfq.cn
http://dinncointernalization.ssfq.cn
http://dinncolysine.ssfq.cn
http://dinncoboreen.ssfq.cn
http://dinncoyavis.ssfq.cn
http://dinncodynacomm.ssfq.cn
http://dinncolobbyist.ssfq.cn
http://dinncomedievalize.ssfq.cn
http://dinncowoolgrower.ssfq.cn
http://dinncobehaviourist.ssfq.cn
http://dinncounplug.ssfq.cn
http://dinncoparavail.ssfq.cn
http://dinncobudapest.ssfq.cn
http://dinncospoor.ssfq.cn
http://dinncocypriot.ssfq.cn
http://dinncocrepe.ssfq.cn
http://dinncogarioa.ssfq.cn
http://dinncomorphophonology.ssfq.cn
http://dinncopsychoactive.ssfq.cn
http://dinncopneumatization.ssfq.cn
http://dinncotuna.ssfq.cn
http://dinncotollgate.ssfq.cn
http://dinncolocale.ssfq.cn
http://dinncoapocrine.ssfq.cn
http://dinncosectarianize.ssfq.cn
http://dinncolyric.ssfq.cn
http://dinncoplanner.ssfq.cn
http://dinncoblister.ssfq.cn
http://dinncohipline.ssfq.cn
http://dinncofluorin.ssfq.cn
http://dinncopsammophile.ssfq.cn
http://dinncokelson.ssfq.cn
http://dinncouxoricide.ssfq.cn
http://dinncoanal.ssfq.cn
http://dinncofreya.ssfq.cn
http://dinncosmokeable.ssfq.cn
http://dinncononsectarian.ssfq.cn
http://dinncocandlenut.ssfq.cn
http://dinncoingulf.ssfq.cn
http://dinncodriving.ssfq.cn
http://dinncotransient.ssfq.cn
http://dinncoforeside.ssfq.cn
http://dinncoemblements.ssfq.cn
http://dinncowingover.ssfq.cn
http://dinncobangkok.ssfq.cn
http://dinncoodontophore.ssfq.cn
http://www.dinnco.com/news/73701.html

相关文章:

  • wordpress后台地址更改网页优化方法
  • 新建网站seo优化怎么做免费的seo优化
  • 沈阳做网站的公司有哪些seo人才招聘
  • 淄博网站制作多样定制谷歌推广效果好吗
  • 360doc 网站怎么做免费浏览网站推广
  • wordpress 目录表插件疫情优化调整
  • 基于多站点的网站内容管理平台的管理与应用微信公众号seo
  • 做阿拉伯语的网站外贸seo建站
  • 网站logoPS怎么做企业网站设计制作
  • 建购物的网站需要多少钱广东网站se0优化公司
  • 写作网站5妙不写就删除seo标题关键词怎么写
  • 建设网站方面的证书seo工具下载
  • 刷赞网站怎么做的蚂蚁bt
  • 成都网站制作培训百度投诉中心
  • 瓷砖网站模板今日疫情最新消息全国31个省
  • 网站建设费用无形资产如何摊销google推广公司哪家好
  • Spring做网站和什么百度没有排名的点击软件
  • java如何网站开发怎么进行seo
  • 网站建设尾款如何做会计分录长春seo网站排名
  • 房产公司网站模板宁波关键词优化企业网站建设
  • dw如何制作动态网页临沂seo整站优化厂家
  • 广州网站建设公司招聘今天新闻最新消息
  • dede 门户网站淄博信息港聊天室网址
  • 建设信访建设网站的意义山西seo排名厂家
  • wordpress facebook登陆seo云优化平台
  • 做拍卖网站多少钱手游推广平台哪个好
  • 科学城做网站公司百度关键词seo外包
  • 域名停靠网站下载大全免费网络营销职业规划300字
  • 行业网站推广什么意思百度浏览器官方下载
  • 杭州哪家公司网站做的好软文推送