Skip to content

Commit

Permalink
convert hard tabs to 4 spaces in Markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
pityonline committed Jun 18, 2018
1 parent 875b509 commit 0d1d3e7
Show file tree
Hide file tree
Showing 6 changed files with 1,125 additions and 1,126 deletions.
168 changes: 84 additions & 84 deletions concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ package concurrency
type WebsiteChecker func(string) bool

func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
results := make(map[string]bool)
results := make(map[string]bool)

for _, url := range urls {
results[url] = wc(url)
}
for _, url := range urls {
results[url] = wc(url)
}

return results
return results
}
```

Expand All @@ -36,41 +36,41 @@ Here's the test they've written:
package concurrency

import (
"reflect"
"testing"
"reflect"
"testing"
)

func mockWebsiteChecker(url string) bool {
if url == "waat://furhurterwe.geds" {
return false
}
return true
if url == "waat://furhurterwe.geds" {
return false
}
return true
}

func TestCheckWebsites(t *testing.T) {
websites := []string{
"http://google.com",
"http://blog.gypsydave5.com",
"waat://furhurterwe.geds",
}

actualResults := CheckWebsites(mockWebsiteChecker, websites)

want := len(websites)
got := len(actualResults)
if want != got {
t.Fatalf("Wanted %v, got %v", want, got)
}

expectedResults := map[string]bool{
"http://google.com": true,
"http://blog.gypsydave5.com": true,
"waat://furhurterwe.geds": false,
}

if !reflect.DeepEqual(expectedResults, actualResults) {
t.Fatalf("Wanted %v, got %v", expectedResults, actualResults)
}
websites := []string{
"http://google.com",
"http://blog.gypsydave5.com",
"waat://furhurterwe.geds",
}

actualResults := CheckWebsites(mockWebsiteChecker, websites)

want := len(websites)
got := len(actualResults)
if want != got {
t.Fatalf("Wanted %v, got %v", want, got)
}

expectedResults := map[string]bool{
"http://google.com": true,
"http://blog.gypsydave5.com": true,
"waat://furhurterwe.geds": false,
}

if !reflect.DeepEqual(expectedResults, actualResults) {
t.Fatalf("Wanted %v, got %v", expectedResults, actualResults)
}
}
```

Expand All @@ -87,24 +87,24 @@ effect of our changes.
package concurrency

import (
"testing"
"time"
"testing"
"time"
)

func slowStubWebsiteChecker(_ string) bool {
time.Sleep(20 * time.Millisecond)
return true
time.Sleep(20 * time.Millisecond)
return true
}

func BenchmarkCheckWebsites(b *testing.B) {
urls := make([]string, 100)
for i := 0; i < len(urls); i++ {
urls[i] = "a url"
}

for i := 0; i < b.N; i++ {
CheckWebsites(slowStubWebsiteChecker, urls)
}
urls := make([]string, 100)
for i := 0; i < len(urls); i++ {
urls[i] = "a url"
}

for i := 0; i < b.N; i++ {
CheckWebsites(slowStubWebsiteChecker, urls)
}
}
```

Expand Down Expand Up @@ -164,15 +164,15 @@ package concurrency
type WebsiteChecker func(string) bool

func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
results := make(map[string]bool)
results := make(map[string]bool)

for _, url := range urls {
go func() {
results[url] = wc(url)
}()
}
for _, url := range urls {
go func() {
results[url] = wc(url)
}()
}

return results
return results
}
```

Expand Down Expand Up @@ -234,17 +234,17 @@ import "time"
type WebsiteChecker func(string) bool

func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
results := make(map[string]bool)
results := make(map[string]bool)

for _, url := range urls {
go func() {
results[url] = wc(url)
}()
}
for _, url := range urls {
go func() {
results[url] = wc(url)
}()
}

time.Sleep(2 * time.Second)
time.Sleep(2 * time.Second)

return results
return results
}
```

Expand Down Expand Up @@ -272,23 +272,23 @@ To fix this:
package concurrency

import (
"time"
"time"
)

type WebsiteChecker func(string) bool

func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
results := make(map[string]bool)
results := make(map[string]bool)

for _, url := range urls {
go func(u string) {
results[u] = wc(u)
}(url)
}
for _, url := range urls {
go func(u string) {
results[u] = wc(u)
}(url)
}

time.Sleep(2 * time.Second)
time.Sleep(2 * time.Second)

return results
return results
}
```

Expand Down Expand Up @@ -411,26 +411,26 @@ package concurrency

type WebsiteChecker func(string) bool
type result struct {
string
bool
string
bool
}

func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
results := make(map[string]bool)
resultChannel := make(chan result)
results := make(map[string]bool)
resultChannel := make(chan result)

for _, url := range urls {
go func(u string) {
resultChannel <- result{u, wc(u)}
}(url)
}
for _, url := range urls {
go func(u string) {
resultChannel <- result{u, wc(u)}
}(url)
}

for i := 0; i < len(urls); i++ {
result := <-resultChannel
results[result.string] = result.bool
}
for i := 0; i < len(urls); i++ {
result := <-resultChannel
results[result.string] = result.bool
}

return results
return results
}
```

Expand Down
Loading

0 comments on commit 0d1d3e7

Please sign in to comment.