Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 12, 2023

Conversation

kke
Copy link
Contributor

@kke kke commented Nov 8, 2023

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

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!

Copy link
Member

@camdencheek camdencheek left a comment

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
2 checks passed
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