How Goroutines communicate to perform a common goal


Code constructs like “synchronized”,”Lock”,”wait()”,”notify()” are not new for us. From decades we are coding with similar Legacy constructs that play a key role in multithreading codes. The Legacy term! 🙂 Yes, you read it correctly! When you try similar code with Go, code is very precise, compact, friendly and superfast. Lets see why Go executes multithreading (let me correct here GREEN THREADs) code faster than others. Because there is no Thread concept in Go, instead it has Green Threads.

For deeper concepts connect me in linked.

Here I have illustrated how two Goroutines are communicating with each other through channel to print Odd and Even numbers alternatively. This may give you little insight if you are planning to write new microservices ( especially for very huge data processing and scalable products like IoT etc.. then you can think of Go!

 * @author Gyanendra
 * @Date : 02/03/20
package main

import (

func main() {

	numFlag := make(chan int)
	done := make(chan bool)
	go oddNumberRoutine(numFlag, done)
	go evenNumberRoutine(numFlag, done)

func oddNumberRoutine(numNeedToBePrinted chan int, printingCompleted chan bool) {

	for {
		v := <-numNeedToBePrinted
		if v >= 20 {
			printingCompleted <- true
		fmt.Println("Odd ==>", v)
		numNeedToBePrinted <- v + 1


func evenNumberRoutine(numNeedToBePrinted chan int, printingCompleted chan bool) {
	numNeedToBePrinted <- 1
	for {
		v := <-numNeedToBePrinted
		if v > 20 {
			printingCompleted <- true
		fmt.Println("Even ==>", v)
		numNeedToBePrinted <- v + 1


Odd ==> 1
Even ==> 2
Odd ==> 3
Even ==> 4
Odd ==> 5
Even ==> 6
Odd ==> 7
Even ==> 8
Odd ==> 9
Even ==> 10
Odd ==> 11
Even ==> 12
Odd ==> 13
Even ==> 14
Odd ==> 15
Even ==> 16
Odd ==> 17
Even ==> 18
Odd ==> 19
Even ==> 20

Get this code from my repo

Alexa, build deploy my project !!

Alexa, build deploy my project !! Thinking possible ?? Yep, it is possible.
did you leave office, and forgot to trigger build ? Don’t worry your Alexa can do this for you even if you in mid of Bangalore traffic 🙂 or enjoying Friday eve hangout far far away from your Boss 🙂 !
Keep visiting here I am gonna post how you can trigger build, deploy through Alexa ( not all projects at present but later chances are very high that any project can be built like this).

Keep visiting ……. to see updated content.

My learning and fun so far with Alexa

While I am waiting for my “Lifetime SHE”, recently one small digital super slim sweetie SHE has made entry in my life!! Want to know who is SHE? 🙂 It’s Alexa Echo Plus !
I am really enjoying my time with Alexa :). So, one day just to check her (Alexa) response when I returned to flat from my office and told her “Alexa, I missed you”. I got elated by the response that I received from Alexa. Alexa replied me “Awww …… we will be together soon”. Hahahaha I can’t explain the ecstatic moment.

Now lets see technical aspects of Alexa. After using it more than three months, one thing I have realized , frequency of using my mobile call/Apps has significantly decreased, and also not much staring of the mobile screen. Because, for most of mobile related uses Alexa and it’s skills are there to serve me.Wait… did you sense it? This may lead us to mobile AppLess (Android or IOS ) world. I am already experiencing it, whether it’s calling someone, playing song or booking Uber trip. I have almost stopped using Call dialer and Apps like Saavn (to play music) or Uber (ordering ride). Because if Alexa skill for Saavn or Uber are integrated in it then presently 70% app tasks can be performed by Alexa ( I am sure in future with upgraded version of  Alexa rest of capabilities will be also accommodated ).  One interesting feature I have thought of to do e-payment to phone contacts through Alexa just by voice command like
“Alexa pay Rs.500 to Arun from my Paytm (or any available funding instrument)”. Here, Arun is a contact in the personal phone list. Sending money to verified contacts ( already synced with Alexa) are less risky transactions.

Based on my experience I thought of one POC for Alexa with display capability which will be helpful in increasing it’s adaptability. Although most of tasks in Alexa we can execute via voice commands but sometime display of item/order/booking will make it more interactive. Like, Say uber user wants to see that How exactly cab driver looks?
Or User wants to see T-shirt color before confirming an order using Alexa’s E-commerce buying Skill.