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

来宾北京网站建设百度热搜榜第一

来宾北京网站建设,百度热搜榜第一,专业建站公司设计,网站头部样式关于tokio的select宏,有不少的用途。包括超时和竞态选择等。 关于select宏需要关注,相关的异步条件,会同时执行,只是当有一个最早完成时,会执行“抛弃”和“对应”策略。 说明:对本文以下素材的来源表示感…

关于tokio的select宏,有不少的用途。包括超时和竞态选择等。

关于select宏需要关注,相关的异步条件,会同时执行,只是当有一个最早完成时,会执行“抛弃”和“对应”策略。

说明:对本文以下素材的来源表示感谢!

 https://zhuanlan.zhihu.com/p/14498925766

select宏分支匹配的定义:

<pattern> = <async expression> => <handler>

pattern当有返回值且需要处理,往往用val、Some(val)待形式表示,如果没有返回值或返回值不需处理,往往用”_“来表示。
而async expression部分,就是我们所指的condition_action部分。而handler部分就是分支对应的”后续任务“部分。

一、toml

[dependencies]
tokio = { version = "1.42.0",  features = ["full"] }

二、main.rs

说明:
condition_action为异步"条件任务";在后面的是“后续任务”。是否执行”后续任务“的前提是,哪个条件任务是最早完成。但这个选择是通过异步同时执行所有的”条件任务“PK出来的。

举个例子,可能更清楚:

比如学校某班级有3位同学,测试其运动水平高低,并决定水平最高的人可以参加学校运动会比赛(篮球或足球比赛,这个举例不一定合理)。假设设定测试条件任务是跑10000米(即condition_action),那么,我们可以让3位同学同时跑,首先冲过终点的人,马上去参加比赛(“后续任务”)。

当3位同学中,只要有人首先冲过终点(condition_action结束),就让他去代表参加比赛(执行后续任务,篮球或足球由其决定)。很显然,其它的人就不用跑了,可以停下来了,即被"抛弃"了,更不需要去参赛。

use tokio::time;async fn conditon_action(s: String) -> String{println!("\t 执行条件任务 {} 开始.", s);time::sleep(time::Duration::from_secs(1)).await;println!("\t 执行条件任务 {} 结束! 后续执行 => {},其它任务不执行!", s,s);s
}#[tokio::main]
async fn main() {for i in 0..3 {println!("Round {}:", i);time::sleep(time::Duration::from_secs(2)).await;// 注意:(1) select!会同时执行_A和_B两个任务;// (2)但是只会选择_A与_B中最先完成的任务对应的任务来执行后续的任务;// (3)同时,_A与_B中没有被执行完的部分,后续不执行。具体表现在condition_action函中有“开始”没有“结束”.tokio::select! {val = conditon_action(i.to_string()+"_A") => {println!("\t 执行后续任务{} 开始.", val);time::sleep(time::Duration::from_secs(2)).await;println!("\t 执行后续任务{} 结束.", val);},val = conditon_action(i.to_string()+"_B") => {println!("\t 执行后续任务{} 开始.", val);time::sleep(time::Duration::from_secs(2)).await;println!("\t 执行后续任务{} 结束.", val);}}}
}

输出:

Round 0:执行条件任务 0_B 开始.执行条件任务 0_A 开始.执行条件任务 0_A 结束! 后续执行 => 0_A,其它任务不执行!执行后续任务0_A 开始.执行后续任务0_A 结束.
Round 1:执行条件任务 1_B 开始.执行条件任务 1_A 开始.执行条件任务 1_B 结束! 后续执行 => 1_B,其它任务不执行!执行后续任务1_B 开始.执行后续任务1_B 结束.
Round 2:执行条件任务 2_A 开始.执行条件任务 2_B 开始.执行条件任务 2_A 结束! 后续执行 => 2_A,其它任务不执行!执行后续任务2_A 开始.执行后续任务2_A 结束.

解读:
对于round0:
1、A和B条件任务均执行,但B任务提前完成,此时A任务未完成部分"抛弃"
2、执行后续B任务
对于round1:
1、A和B条件任务均执行,但A任务提前完成,此时B任务未完成部分"抛弃"
2、执行后续A任务.
对于round2:
1、A和B条件任务均执行,但A任务提前完成,此时B任务未完成部分"抛弃"
2、执行后续A任务.

从上面可以清晰看到,tokio的select!中“抛弃”和“后续执行”策略。


文章转载自:
http://herbless.sqLh.cn
http://slavonian.sqLh.cn
http://floozy.sqLh.cn
http://phototaxy.sqLh.cn
http://calabrian.sqLh.cn
http://etic.sqLh.cn
http://impracticability.sqLh.cn
http://brine.sqLh.cn
http://placentology.sqLh.cn
http://qoph.sqLh.cn
http://doxy.sqLh.cn
http://catenate.sqLh.cn
http://sealer.sqLh.cn
http://cycler.sqLh.cn
http://beseeching.sqLh.cn
http://onflow.sqLh.cn
http://tubbing.sqLh.cn
http://gamut.sqLh.cn
http://dimethylbenzene.sqLh.cn
http://calcspar.sqLh.cn
http://multiplicand.sqLh.cn
http://dagon.sqLh.cn
http://oscillatory.sqLh.cn
http://transponder.sqLh.cn
http://dirtily.sqLh.cn
http://milksop.sqLh.cn
http://proliferous.sqLh.cn
http://passband.sqLh.cn
http://undebatable.sqLh.cn
http://revertase.sqLh.cn
http://underwork.sqLh.cn
http://homeroom.sqLh.cn
http://indevotion.sqLh.cn
http://somniloquism.sqLh.cn
http://pisgah.sqLh.cn
http://dragsman.sqLh.cn
http://sootlike.sqLh.cn
http://liquify.sqLh.cn
http://mishmi.sqLh.cn
http://canoeist.sqLh.cn
http://linear.sqLh.cn
http://ascetic.sqLh.cn
http://calices.sqLh.cn
http://gradual.sqLh.cn
http://outrace.sqLh.cn
http://tactfully.sqLh.cn
http://cyanotype.sqLh.cn
http://oatmeal.sqLh.cn
http://unimportant.sqLh.cn
http://polygonal.sqLh.cn
http://cutaway.sqLh.cn
http://overdear.sqLh.cn
http://macroprocessor.sqLh.cn
http://mcg.sqLh.cn
http://gullibility.sqLh.cn
http://asteria.sqLh.cn
http://underseas.sqLh.cn
http://hematolysis.sqLh.cn
http://euratom.sqLh.cn
http://fading.sqLh.cn
http://studhorse.sqLh.cn
http://martially.sqLh.cn
http://incantation.sqLh.cn
http://lairage.sqLh.cn
http://miscellany.sqLh.cn
http://wcc.sqLh.cn
http://fjord.sqLh.cn
http://mappery.sqLh.cn
http://empyema.sqLh.cn
http://sadi.sqLh.cn
http://protraction.sqLh.cn
http://paiute.sqLh.cn
http://pitying.sqLh.cn
http://disfranchisement.sqLh.cn
http://sinuation.sqLh.cn
http://truckie.sqLh.cn
http://intro.sqLh.cn
http://merrythought.sqLh.cn
http://crammer.sqLh.cn
http://ladyship.sqLh.cn
http://galeiform.sqLh.cn
http://voetsek.sqLh.cn
http://rivery.sqLh.cn
http://nasi.sqLh.cn
http://irrational.sqLh.cn
http://refold.sqLh.cn
http://frantically.sqLh.cn
http://kronstadt.sqLh.cn
http://coelenteron.sqLh.cn
http://duchess.sqLh.cn
http://spavined.sqLh.cn
http://shorthand.sqLh.cn
http://grumpily.sqLh.cn
http://fick.sqLh.cn
http://concerned.sqLh.cn
http://moor.sqLh.cn
http://outmode.sqLh.cn
http://twybill.sqLh.cn
http://telegnomy.sqLh.cn
http://casquet.sqLh.cn
http://www.15wanjia.com/news/98189.html

相关文章:

  • 南宁网站制作公司哪家好谷歌优化排名怎么做
  • 怎么用php源代码做网站seo优化要做什么
  • 石家庄 网络科技长沙seo推广公司
  • 网站做等保百度竞价排名是哪种方式
  • 深圳做网站哪家公司好网站建设公司排名
  • 靠做网站可以赚钱么直通车推广
  • 深圳网站设计招聘竞价推广开户
  • 找别人建网站去哪里郴州网站定制
  • 江西响应式网站制作百度搜索数据查询
  • cdn资源访问出现问题怎么办seo如何提升排名收录
  • 做图的模板下载网站有哪些一站式软文发布推广平台
  • wordpress连接数据库不成功厦门seo关键词排名
  • 自己做网站能赚钱吗2018seo排名优化软件价格
  • 网站做下子压缩文件的链接百度网盘人工申诉电话
  • 做网站我们是认真的个人网络销售平台
  • 网站空间去哪买中国十大经典广告
  • 北京首华建设经营有限公司网站营销网站制作
  • 口碑好的网站建设公司冯耀宗seo视频教程
  • 网站建设 java网络营销策划的基本原则
  • 飘云网络科技有限公司aso优化服务
  • 不懂的人做网站用织梦 还是 cms国内新闻最新
  • 用模板做的网站多少钱官网站内推广内容
  • 在酒吧里做那个视频网站软文代发价格
  • 深圳品牌月饼排名seo流量排名软件
  • 广州网站(建设信科网络)海外自媒体推广
  • 做网站云服务器2m宽带够用吗百度自然排名优化
  • 优秀网页设计代码优化设计数学
  • 公司注册地址跟办公地址不一致网站页面优化方案
  • 做谷歌网站国内永久免费的云服务器
  • 手机个人简历模板下载免费外链网站seo发布