Skip to content

Modern Chan Add

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Goroutines and Channels › Goroutines and Channels › Add

Add

Adds 1, or a given amount, to the work outstanding; call it before the spawn.

Syntax

Add( delta = 1 )

Examples

#import "std/tasks"
using tasks

'' A WaitGroup counts outstanding work. Add BEFORE spawning, never
'' inside the goroutine -- otherwise Wait( ) can see zero and return
'' before the worker has even started.
dim wg as WaitGroup

wg.Add( )                    '' delta defaults to 1
print wg.Count( )            '' 1

wg.Add( 3 )                  '' or several at once
print wg.Count( )            '' 4

wg.Done( ) : wg.Done( ) : wg.Done( ) : wg.Done( )
print wg.Count( )            '' 0

Library: Goroutines and Channels
Category: Goroutines and Channels
Documented under: Waitgroup

Clone this wiki locally