Use of Timer

Hello,

I would like to make a text appear and have each letter appear at X seconds intervals. I think it is possible to do this with the Timer function but I don’t know how to use it. I had thought of using an array that would contain the letters but how to do it ?
Still concerning the use of Timer: how to make a function run automatically Y seconds after another function has been run?

The only example I found about Timer is this one:

begin
           i = 0
           cb(timer) = (global i += 1; println(i))
           t = Timer(cb, 2, interval=0.2)
           wait(t)
           sleep(0.5)
           close(t)
       end

Thank you

You could rig something up using Timer, but it’s much simpler to do this without:

function print_slowly(s, interval)
    for c in s
        sleep(interval)
        print(c)
    end
end

Is there a particular reason you’d like to use Timer for this? The Timer-based solution is below:

function print_slowly(s, interval)
    timer = Timer(0; interval=interval)
    for c in s
        wait(timer)
        print(c)
    end
    close(timer)
end
1 Like

No there is no particular reason, I thought it was the only solution.
Your solution works but since I work with Pluto and use “with_terminal() do”, the function runs in full and the result appears in full. It does not appear little by little respecting the intervals.

I don’t think there’s any way to do this within Pluto. See the answer to the question “Can I
use @async to update values reactively on demand?” on this page:

1 Like