惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

Jia Yue Hua

完美转发不完美 闲散颂 adapting c++20 ranges algorithms for most metaprogramming Reproducible github Developer Environments 使用mpmcpipeline和jthread实现软流水 在其它线程周期回调函数 for_each cpo和tag_invoke transparent,为关联容器增加查找成员
在当前线程周期回调函数
Jia Yue Hua · 2023-05-21 · via Jia Yue Hua

在当前线程周期回调函数

FunctionScheduler 可在当前线程周期回调函数

#include <folly/experimental/FunctionScheduler.h>
#include <iostream>
#include <gtest/gtest.h>
using namespace folly;
using namespace std;
TEST(repeatfunc,repeatfunc) { 
  FunctionScheduler fs;
  fs.addFunction([]() { cout << "Hello, world!" << endl; }, 1s);
  fs.start();
  this_thread::sleep_for(10s);
  fs.cancelAllFunctions();
}

只需要addFunction时指明要回调的函数和时间间隔。调用start启动,当不再需要回调时调用cancelAllFunctions. 本例中,每隔1s打印一次”Hello, world!”,共打印10次。

可以看到,比使用folly eventbase的asynctimer简单很多。

Posted 2023-05-21