Skip to content

Commit

Permalink
Move example to the workerpool_test package
Browse files Browse the repository at this point in the history
Moving the example code out of the workerpool package shows it as
written from the perspective of a real user of the package.

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
  • Loading branch information
rolinh committed Apr 8, 2021
1 parent 6d2e2cd commit a2ae910
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package workerpool
package workerpool_test

import (
"context"
"fmt"
"os"
"runtime"

"github.com/cilium/workerpool"
)

// IsPrime returns true if n is prime, false otherwise.
Expand All @@ -35,7 +37,7 @@ func IsPrime(n int64) bool {
}

func Example() {
wp := New(runtime.NumCPU())
wp := workerpool.New(runtime.NumCPU())
for i, n := 0, int64(1_000_000_000_000_000_000); n < 1_000_000_000_000_000_100; i, n = i+1, n+1 {
n := n // https://golang.org/doc/faq#closures_and_goroutines
id := fmt.Sprintf("task #%d", i)
Expand Down

0 comments on commit a2ae910

Please sign in to comment.