Skip to content

Use *_test packages to make examples copy-pasteable#124

Merged
camdencheek merged 2 commits into
sourcegraph:mainfrom
kke:use-test-packages
Nov 12, 2023
Merged

Use *_test packages to make examples copy-pasteable#124
camdencheek merged 2 commits into
sourcegraph:mainfrom
kke:use-test-packages

Conversation

@kke

@kke kke commented Nov 8, 2023

Copy link
Copy Markdown
Contributor

The main reason for this PR was to make the examples in documentation
copy-pasteable, but there are some additional benefits too.

For example, the pool example before this change:

p := New().WithMaxGoroutines(3)
for i := 0; i < 5; i++ {
	p.Go(func() {
		fmt.Println("conc")
	})
}
p.Wait()

and after:

p := pool.New().WithMaxGoroutines(3) // has package name
for i := 0; i < 5; i++ {
	p.Go(func() {
		fmt.Println("conc")
	})
}
p.Wait()

The function defaultMaxGoroutines in iter package had to be exported because it was used from the tests.

kke added 2 commits November 8, 2023 12:09
The main reason for this PR is to make the examples in documentation
copy-pastable.

For example, the pool example before this change:

```go
p := New().WithMaxGoroutines(3)
for i := 0; i < 5; i++ {
	p.Go(func() {
		fmt.Println("conc")
	})
}
p.Wait()
```

and after:

```go
p := pool.New().WithMaxGoroutines(3) // has package name
for i := 0; i < 5; i++ {
	p.Go(func() {
		fmt.Println("conc")
	})
}
p.Wait()
```

There are some additional benefits.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #124 (4f9a721) into main (b3c39d3) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #124   +/-   ##
=======================================
  Coverage   99.31%   99.31%           
=======================================
  Files          12       12           
  Lines         441      441           
=======================================
  Hits          438      438           
  Misses          3        3           

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Neat trick -- that's a new one for me. Thanks!

@camdencheek camdencheek merged commit abd9a8b into sourcegraph:main Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants