• Is this the correct way to wait in a coroutine

    From Cecil Westerhof@21:1/5 to All on Thu Nov 25 12:12:43 2021
    Yesterday I discovered coroutines. A very handy tool.

    I have the following code:
    proc startVmstatLogging {} {
    coroutine vmstatLogging apply {{} {
    set command "|env TZ=UTC vmstat -n -S M -t 60 5"
    after [getWaitMinutesTicks 1] [info coroutine]
    yield
    set vmstat [open ${command} RDONLY]

    I want the vmstat command to be opened as close at possible. With
    [getWaitMinutesTicks 1]

    I get the number of ticks until the start of the next minute.
    Is this the correct way to wait until the next minute without
    blocking, or is there a better way?

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to Cecil Westerhof on Thu Nov 25 16:24:38 2021
    On 25/11/2021 12:12, Cecil Westerhof wrote:
    after [getWaitMinutesTicks 1] [info coroutine]
    yield

    Is this the correct way to wait until the next minute without
    blocking, or is there a better way?

    While this will work most of the time, it is not completely correct. The problem arises if your coroutine name contains one or more spaces. So,
    the correct way is to use:
    after [getWaitMinutesTicks 1] [list [info coroutine]]

    An alternative would be to use [coroutine::util after] from tcllib.
    Whether that is better, is your judgement.


    Schelte

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Schelte on Fri Nov 26 14:27:55 2021
    Schelte <nospam@wanadoo.nl> writes:

    On 25/11/2021 12:12, Cecil Westerhof wrote:
    after [getWaitMinutesTicks 1] [info coroutine]
    yield

    Is this the correct way to wait until the next minute without
    blocking, or is there a better way?

    While this will work most of the time, it is not completely correct.
    The

    Good that I asked a question then.


    problem arises if your coroutine name contains one or more spaces. So,
    the correct way is to use:
    after [getWaitMinutesTicks 1] [list [info coroutine]]

    An alternative would be to use [coroutine::util after] from tcllib.
    Whether that is better, is your judgement.

    Yes, that is much better. Got rid of that ugly yield. I now have
    (only):
    coroutine::util after [getWaitMinutesTicks 1]

    Thanks.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)