August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this subsection, you will learn how to create a variable number of goroutines. The program reviewed in this section is called create.go. It is going to be presented in four parts, and it will allow you to create a dynamic number of goroutines. The number of goroutines will be given as a command-line argument to the program, which uses the flag package to process its command-line argument.
The first code part of create.go is as follows:
package main
import (
"flag"
"fmt"
"time"
)
The second code segment from create.go contains the following Go code:
func main() {
n := flag.Int("n", 10, "Number of goroutines")
flag.Parse()
count := *n
fmt.Printf("Going to create %d goroutines.\n", count)
The preceding code ...
Read now
Unlock full access