Skip to content

This repository explores the usage of go routines in GoLang.

Notifications You must be signed in to change notification settings

marciobera/go-routines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Routines Explorations

This repository explores the usage of go routines in GoLang.
The examples demonstrate practical applications using channels, context and concurrency management.

Make sure that you have installed go 1.22.1 or higher to run these examples.

1. Using context.WithCancel

Booking Process

The booking process ensures that room booking proceeds only if the room is available. Otherwise, it cancels all booking processes.

To run the booking process, execute the following command:

go run booking/main.go

2. Using http.Request.Context

Server Operations

The server component runs a backend server capable of processing or rejecting requests based on the request context.

To run the server, execute the following command:

go run server/main.go

To test this server as a client, use the following command:

curl localhost:8080

3. Using context.WithTimeout

Client Request with Timeout

This example demonstrates a client application utilizing context with a timeout to enforce a request failure if the context deadline is exceeded.

To run this client example, execute the following command:

go run client/main.go

For a comprehensive demonstration, run this client alongside the server/main.go. This setup will illustrate the expected results for each side, showcasing the timeout behavior and its impact on request handling.

4. Using chan and sync.WaitGroup

Parallel tasks

This example demonstrates a execution of parallel tasks utilizing channels and waiting groups.

To run this client example, execute the following command:

go run channel/main.go

About

This repository explores the usage of go routines in GoLang.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages