gocount

package module
v0.0.0-...-bbe34e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2016 License: BSD-2-Clause Imports: 3 Imported by: 0

README

GoCount

This is a simple package with just one purpose: count the number of running goroutines that are not runtime goroutines. It is different from runtime.NumGoroutine, as that function counts all goroutines (including e.g. garbage collection goroutines).

Example:

package main

import (
    "github.com/aykevl/gocount"
    "fmt"
)

func main() {
    fmt.Println("Number of running goroutines:", gocount.Number())

    block := make(chan struct{})
    done := make(chan struct{})

    fmt.Print("hello, ")

    go func() {
        fmt.Println("world")
        done <- struct{}{}
        <-block
    }()
    <-done

    fmt.Println("Number of running goroutines:", gocount.Number())
}

Output:

Number of running goroutines: 1
hello, world
Number of running goroutines: 2

The package is licensed under the 3-clause BSD license.

Documentation

Overview

Package gocount counts the number of goroutines currently running. It should only be used for testing purposes, as it is implemented in a very inefficient way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Number

func Number() int

Number returns the number of goroutines, not including runtime goroutines like those created by the garbage collector.

Also take a look at runtime.NumGoroutine(), which counts all goroutines including those created by the runtime.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL