TABLE OF CONTENTS


::pwtk::bg_wait

SYNOPSIS

proc ::pwtk::bg_wait {args} {

USAGE

   bg_wait ?-s? ?bg_id1? ?bg_id2 ...?

PURPOSE

Wait for the specified pwtk::bg (aka background) jobs to finish.

If called without arguments, the command waits for all the pwtk::bg (aka background) jobs to finish.

OPTION

ARGUMENTS

SOURCE

    variable bg
    variable time_interval_ms

    set silent 0
    if { [lindex $args 0] eq "-s" } {
        set silent 1
        set args [lrange $args 1 end]
    }    
    if { $args eq "" } {
        set args [seq 1 $bg(count)]
    }
    if { [llength $args] == 1 } {
        set args [concat {*}$args]
    }
    if { ! [::pwtk::type::numberlist integer -strict $args] } {
        ::pwtk::error "expecting list of integers for job IDs, but got $args" 1
    }

    if { [llength $args] > 1 } { set s s }
    if { ! $silent } {
        print [concat Waiting for the background job[varvalue s] [join $args {, }] to finish ...]\n
    }

    foreach id $args {
        while { [info exists bg($id,chan)] } {
            vwait ::pwtk::bg($id,done)
        }
    }
}