1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 11:03:37 +03:00
mobile-nixos/boot/init/tasks/target.rb
Samuel Dionne-Riel a3c8cd78e8 boot/init: Sort tasks before running them
This is partly to reduce the amount of loops it needs to run, but mainly
to control the order rather than rely on the order they were added in.

The control of order seems weird in a dependency-based system, but it'll
be used mainly for one thing in the next commit...
2020-02-03 16:19:10 -05:00

33 lines
882 B
Ruby

# Use this task to define a "well-known" task that can be depended upon to stop
# execution until multiple tasks have been fulfilled.
#
# An example is to make a Target that depends on all mount points needed for
# booting the system, and the task that boots depend on that target.
#
# This removes the need of the final tasks depending on the target to need to
# know about the dependencies.
#
# Prefer actually depending on discrete tasks rather than targets. Use targets
# only to describe a vague step that may be fulfilled by different
# implementations.
class Tasks::Target < Task
def initialize(name)
@name = name.to_sym
end
def run(); end
def name()
"#{super}<#{@name}>"
end
end
module Targets
def self.[](name)
name = name.to_sym
@targets ||= {}
@targets[name] = Tasks::Target.new(name) unless @targets[name]
@targets[name]
end
end