-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from alitto/feature/1.7.0
Pool context option & stop with timeout
- Loading branch information
Showing
12 changed files
with
282 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
name: Build | ||
jobs: | ||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
go-version: [1.15.x, 1.16.x, 1.17.x] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Test | ||
run: go test -race -v ./ | ||
codecov: | ||
name: Upload coverage report to Codecov | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Test | ||
run: go test -race -v -coverprofile=coverage.txt -covermode=atomic ./ | ||
- uses: codecov/codecov-action@v2 | ||
with: | ||
files: ./coverage.txt | ||
fail_ci_if_error: true | ||
verbose: true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/alitto/pond/examples/pool_context | ||
|
||
go 1.17 | ||
|
||
require github.com/alitto/pond v1.6.1 | ||
|
||
replace github.com/alitto/pond => ../../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"time" | ||
|
||
"github.com/alitto/pond" | ||
) | ||
|
||
// Pressing Ctrl+C while this program is running will cause the program to terminate gracefully. | ||
// Tasks being processed will continue until they finish, but queued tasks are cancelled. | ||
func main() { | ||
|
||
// Create a context that will be cancelled when the user presses Ctrl+C (process receives termination signal). | ||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) | ||
defer stop() | ||
|
||
// Create a pool and pass the context to it. | ||
pool := pond.New(1, 1000, pond.Context(ctx)) | ||
defer pool.StopAndWait() | ||
|
||
// Submit several long runnning tasks | ||
var count int = 100 | ||
for i := 0; i < count; i++ { | ||
n := i | ||
pool.Submit(func() { | ||
fmt.Printf("Task #%d started\n", n) | ||
time.Sleep(1 * time.Second) | ||
fmt.Printf("Task #%d finished\n", n) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.