Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kinfinity committed Mar 20, 2024
1 parent 3afc929 commit 890efd0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 37 additions & 0 deletions timeout/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Timeout Pattern in Go

The Timeout pattern is used to limit the execution time of a function or operation. It ensures that the operation completes within a specified time duration, and if it exceeds that duration, it either returns a default value or invokes a fallback function.

## Usage

```go
package main

import (
"context"
"fmt"
"time"

"github.com/kinfinity/distributed-resilience/timeout"
)

func main() {
// Create a Timeout instance with a fallback function
timeout := timeout.NewTimeOutWithFallback(5 * time.Second, func() error {
// Custom fallback logic here
return nil
})

// Watch for timeout
result := timeout.Watch(executionCompletionChan)
if result.result {
// Operation completed within the timeout duration
} else {
// Operation timed out
}
}
```

# **References**

- [codecentric resilience-design-patterns](https://www.codecentric.de/wissens-hub/blog/resilience-design-patterns-retry-fallback-timeout-circuit-breaker)
1 change: 0 additions & 1 deletion timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"time"

)

// Timeout
Expand Down

0 comments on commit 890efd0

Please sign in to comment.