<commit_before># parallel

[![Build Status](https://travis-ci.org/w0wik/parallel.svg?branch=master)](https://travis-ci.org/w0wik/parallel)
[![GoDoc](https://godoc.org/github.com/w0wik/parallel?status.svg)](https://godoc.org/github.com/w0wik/parallel)

Collection of parallel and async wrappers for thread safe programming written in golang (http://golang.org)

To install:

	go get github.com/w0wik/parallel

See docs for usage:
	https://godoc.org/github.com/w0wik/parallel

#### AsyncMap Example
```go
package main

import (
	"fmt"

	"github.com/w0wik/parallel"
)

func main() {
	m := parallel.NewAsyncMap(1)
	defer m.Close()
	m.Set(1) <- "hello"
	fmt.Println(<-m.Get(1))
	<-m.Delete(1)

}
```

#### ConditionVariable Example
```go
package main

import (
	"fmt"
	"os"
	"os/signal"
	"time"

	"github.com/w0wik/parallel"
)

func wait(cv *parallel.ConditionVariable, n int) {
	cv.Wait()
	fmt.Println("Done waitng", n)
}

func main() {
	cv := parallel.NewConditionVariable()

	// 3 goroutines waits notify
	go wait(cv, 1)
	go wait(cv, 2)
	go wait(cv, 3)

	time.Sleep(time.Millisecond * 10)

	// 1 goroutine stops waiting
	cv.NotifyOne()

	// other goroutines stop waiting
	cv.NotifyAll()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	<-c
}
```
#### Monitor Example
```go
package main

import (
	"fmt"
	"os"
	"os/signal"
	"time"

	"github.com/w0wik/parallel"
)

func main() {
	sl := make([]int, 0)
	mon := parallel.NewMonitor(&sl)

	go mon.Access(func(s *[]int) {
		*s = append(*s, 1)
	})
	go mon.Access(func(s *[]int) {
		*s = append(*s, 2)
	})<commit_msg>read me update<commit_after># parallel

[![Build Status](https://travis-ci.org/w0wik/parallel.svg?branch=master)](https://travis-ci.org/w0wik/parallel)
[![GoDoc](https://godoc.org/github.com/w0wik/parallel?status.svg)](https://godoc.org/github.com/w0wik/parallel)

Collection of parallel and async wrappers for thread safe programming written in [golang](http://golang.org)

To install:

	go get github.com/w0wik/parallel

See docs for usage:
	https://godoc.org/github.com/w0wik/parallel

#### AsyncMap Example
```go
package main

import (
	"fmt"

	"github.com/w0wik/parallel"
)

func main() {
	m := parallel.NewAsyncMap(1)
	defer m.Close()
	m.Set(1) <- "hello"
	fmt.Println(<-m.Get(1))
	<-m.Delete(1)

}
```

#### ConditionVariable Example
```go
package main

import (
	"fmt"
	"os"
	"os/signal"
	"time"

	"github.com/w0wik/parallel"
)

func wait(cv *parallel.ConditionVariable, n int) {
	cv.Wait()
	fmt.Println("Done waitng", n)
}

func main() {
	cv := parallel.NewConditionVariable()

	// 3 goroutines waits notify
	go wait(cv, 1)
	go wait(cv, 2)
	go wait(cv, 3)

	time.Sleep(time.Millisecond * 10)

	// 1 goroutine stops waiting
	cv.NotifyOne()

	// other goroutines stop waiting
	cv.NotifyAll()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	<-c
}
```

#### Monitor Example
```go
package main

import (
	"fmt"
	"os"
	"os/signal"
	"time"

	"github.com/w0wik/parallel"
)

func main() {
	sl := make([]int, 0)
	mon := parallel.NewMonitor(&sl)

	go mon.Access(func(s *[]int) {
		*s = append(*s, 1)
	})
	go mon.Access(func(s *[]int) {
		*s = append(*s, 2)
	})
{'fraction_non_alphanumeric': 0.18400252924438823, 'fraction_numerical': 0.015175466329434081, 'mean_word_length': 3.951486697965571, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '35372', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1259, 'n_words': 269}