Spam Isolation Probe Two
Lesson 2 of 4
Cap the Fan Out
Estimated time: 10 minutes
Cap the Fan Out
One helper that can spawn more helpers turns a small job into a large one. Put a number on how deep the tree goes and stop spawning at the limit.
Count the depth on every task
Stamp each task with its depth and refuse to spawn once the maximum is reached.
def may_spawn(task, max_depth):
return task.depth < max_depth
Let the leaf finish
A worker at the limit completes the work with the tools it has. Returning a plan instead of a result hides a task that never ran.