.Progress~new(0.5)~monitor(.Task~new, "tenSeconds")
-- defines tasks together with their "progress" methods
::class Task
-- long-running task
::method tenSeconds unguarded
expose m n
n = 1000
do m = 1 to n -- long-running task
call SysSleep 0.01
end
return
-- returns running value to be displayed as progress
::method "tenSeconds-progress" unguarded
expose m n
return m"/"n "steps done"
-- runs task while displaying progress text at each interval
::class Progress inherit AlarmNotification
-- set progress interval
::method init unguarded
expose interval
use strict arg interval = 1
-- starts ticker, runs task, and returns task result
-- (requires names of task and progress methods)
::method monitor
expose interval object progress
use strict arg object, task, progress = (task"-progress")
tick = .Ticker~new(interval, self)
object~send(task)
tick~cancel
-- displays progress text at each ticker interval
::method triggered unguarded
expose object progress
.stdout~charOut(object~send(progress) '0d'x)