Tasks & Microtasks
This chapter takes a closer look at both tasks and microtasks.
Tasks
As mentioned in the introduction a task is something that is placed on the “Task/Callback queue” and will be picked up by the runtime and placed onto the Execution stack. For example, if a function calls setTimeout
that will place the function to be executed on the Task/Callback queue once the timer has expired.
Let’s take a look at the output of a concrete example using Node.js
Microtasks
The introduction has some background information about Microtasks. This chapter is going to look into the internals.
Here is an example of running a Microtask with Googletest:
├── lib
│ └── gtest # Output folder
├── test
│ ├── main.cc
│ ├── microtasks_test.cc
│ └── v8_test_fixture.cc
└── Makefile
The Isolate class exposes a number of functions related to enqueueing and running microtasks:
Lets take a look at what happens when we enqueue a microtask function:
$ lldb -- ./test/microtask_test
(lldb) br s -f microtask_test.cc -l 33
(lldb) r
Isolate::EnqueueMicrotask
can be found in src/api/api.cc
The actual call will end up in microtask-queue.cc
which can be found in src/execution/microtask-queue.cc
Back to Chapter Overview