Friday, September 11, 2026

Go routines hack

 If you are running multiple Go Routines in your program and you want your program to not end then do this.

Option 1:

select {}

Note: by using this you are simply blocking till you press ctrl + c.


Option 2:

sigChan := make(chan os.Signal, 1)

signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

<-sigChan 

Note: creating a channel which is expecting a SIGTEM :) ... thats a hack.

No comments:

Post a Comment