Prerequisite: Getting the Code
略
Part 1: Using command-line arguments
main
函数开头需要加上下面的代码设置下日志的输出方式
1 | logging::LoggingSettings settings; |
Part 2: Callbacks and Bind
是个move-only
对象
1 | // The type of a callback that: |
执行的时候要加std::move
1 | void MyFunction1(base::OnceCallback<int(std::string, double)> my_callback) { |
Part 3: Threads and task runners
There are a number of ways to post tasks to a thread pool or task runner.
PostTask()
PostDelayedTask()
if you want to add a delay.PostTaskAndReply()
lets you post a task which will post a task back to your current thread when its done.PostTaskAndReplyWithResult()
to automatically pass the return value of the first call as argument to the second call.