-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throttling pipe with ops per time interval (rate limit) (#55)
* throttling pipe with ops per time interval (rate limit) * update static check GitHub action to v1.3.1
- Loading branch information
Showing
7 changed files
with
146 additions
and
2 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 |
---|---|---|
|
@@ -41,7 +41,7 @@ jobs: | |
flag-name: ${{ matrix.module }} | ||
parallel: true | ||
|
||
- uses: dominikh/[email protected].0 | ||
- uses: dominikh/[email protected].1 | ||
with: | ||
install-go: false | ||
working-directory: ${{ matrix.module }} | ||
|
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,49 @@ | ||
// | ||
// Copyright (C) 2022 - 2024 Dmitry Kolesnikov | ||
// | ||
// This file may be modified and distributed under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
// https://github.com/fogfish/golem | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/fogfish/golem/pipe" | ||
) | ||
|
||
const ( | ||
fastProducer = 10000 | ||
cap = 1 | ||
) | ||
|
||
func main() { | ||
ctx, close := context.WithCancel(context.Background()) | ||
|
||
// Generate sequence of integers | ||
fast := pipe.StdErr(pipe.Unfold(ctx, fastProducer, 0, | ||
func(x int) (int, error) { return x + 1, nil }, | ||
)) | ||
|
||
// Throttle the "fast" pipe | ||
slow := pipe.Throttling(ctx, fast, 1, 100*time.Millisecond) | ||
|
||
// Numbers to string | ||
vals := pipe.StdErr(pipe.Map(ctx, slow, | ||
func(x int) (string, error) { return strconv.Itoa(x), nil }, | ||
)) | ||
|
||
// Output strings | ||
<-pipe.ForEach(ctx, vals, | ||
func(x string) { | ||
fmt.Printf("==> %s | %s\n", time.Now().Format(time.StampMilli), x) | ||
}, | ||
) | ||
|
||
close() | ||
} |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
|
||
package pipe | ||
|
||
const Version = "pipe/v1.1.1" | ||
const Version = "pipe/v1.2.0" |