progression :: Trackable :: defaultinit
# An operation that is trackable using a `ProgressionListener`.
abstract class Trackable
# Listen to the progression of the operation.
var progression_listeners: SimpleCollection[ProgressionListener] =
new Array[ProgressionListener]
# Notice the registered `ProgessionListener` that the operation started.
protected fun fire_started do
for l in progression_listeners do
l.started
l.progressed(0)
end
end
# Notice the registered `ProgessionListener` that the operation progressed.
#
# Parameter:
#
# * `done_part`: Indicates what is done.
# * `total`: Indicates what need to be done, `done_part` included.
protected fun fire_progressed(done_part: Int, total: Int) do
for l in progression_listeners do
l.progressed(done_part * l.progression_max / total)
end
end
# Notice the registered `ProgessionListener` that the operation is done.
protected fun fire_done do
for l in progression_listeners do
l.progressed(l.progression_max)
l.done
end
end
end
lib/progression/progression.nit:14,1--48,3