43 lines
995 B
Markdown
43 lines
995 B
Markdown
## Example Usage:
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
"mcfetch"
|
|
)
|
|
|
|
func main() {
|
|
// Create a channel to receive the result
|
|
resultChan := make(chan map[string]interface{})
|
|
errorChan := make(chan error)
|
|
|
|
// Create an AsyncPlayerFetcher for asynchronous data fetching
|
|
asyncFetcher := mcfetch.NewAsyncPlayerFetcher(
|
|
"Notch", // Minecraft username or UUID
|
|
3, // Number of retries
|
|
2*time.Second, // Retry delay
|
|
5*time.Second, // Request timeout
|
|
)
|
|
|
|
// Start asynchronous data fetching
|
|
asyncFetcher.FetchPlayerDataAsync(resultChan, errorChan)
|
|
|
|
// Non-blocking code execution (do something else while waiting)
|
|
fmt.Println("Fetching data asynchronously...")
|
|
|
|
// Block until we receive data or an error
|
|
select {
|
|
case data := <-resultChan:
|
|
fmt.Printf("Player data: %+v\n", data)
|
|
case err := <-errorChan:
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
``` |