Prabhu Sunderaraman

Fullstack Engineer, Programmer, Writer, Trainer

prabhu.bits@gmail.com,     GitHub     Youtube     LinkedIn
  • Home
  • Profile
  • Books
  • Reading List
Browsing: / Home
Shortlink

Lockdown Learning – Day #49 – Buffered Channels in GoLang (Music Only)

By Prabhu Sunderaraman on May 13, 2020 in Go, Golang

Continuing with our lockdown learning of Go language. Here’s a video where we discuss Buffered Channels in Golang

package main

import (
	"fmt"
	"time"
)

func main() {
	//A channel can buffer data
	//specify buffer size during creation
	ch := make(chan int, 3)
	fmt.Println(cap(ch))
	ch <- 1 //Non Blocking
	ch <- 2 //Non Blocking
	ch <- 3 //Blocking
	go printNum(ch)
	time.Sleep(time.Millisecond)
}

func printNum(ch chan int) {
	fmt.Println(<- ch)
	fmt.Println(<- ch)
	fmt.Println(<- ch)
}


You can watch other videos in Go lang in the links below

Getting Started
Variables and Constants
Data types
Conditional statements
Loops
Arrays
Maps
Slices – I
Slices – II
range
Functions – Part I
Functions – Part II
Closures
types
Type Conversions
struct – Part I
struct – Part II
struct – Part III
Pointers – Part I
Pointers – Part II
interface – Part I
interface – Part II
interface – Part III
interface – Part IV
defer – Part I
defer – Part II
defer – Part III
defer – Part III
panic
panic and recover
panic, recover and defer
Getting started with GoLand IDE.
Getting started with GoLand IDE.
packages.
import packages – Part I.
import packages – Part II.
import packages – Part III.
goroutine – intro .
goroutines & panic.
Waiting for goroutines.
Waitgroup.
Play more with Waitgroup.
<- Channels ->.
<- Exchanging Data using Channels <-.
Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Lockdown Learning – Day #48 – Exchange data using Channels in GoLang (Music Only)

By Prabhu Sunderaraman on May 12, 2020 in Go, Golang

Continuing with our lockdown learning of Go language. Here’s a video where we discuss Exchanging data using Channels in Golang

package main

import "fmt"

func main() {
	channel := make(chan int)

	//Let's square a number in a goroutine
	//Pass the number to the goroutine using channel

	go squareNum(channel)
	channel <- 5
	x := <- channel
	fmt.Println("Squared", x)

	//Let's increment the squared number in a goroutine
	go incrementNum(channel)
	channel <- x
	fmt.Println("Incremented", <- channel)
}

func incrementNum(channel chan int) {
	num := <- channel
	num += 1
	channel <- num
}

func squareNum(channel chan int) {
	num := <- channel
	num *= num
	channel <- num
}



You can watch other videos in Go lang in the links below

Getting Started
Variables and Constants
Data types
Conditional statements
Loops
Arrays
Maps
Slices – I
Slices – II
range
Functions – Part I
Functions – Part II
Closures
types
Type Conversions
struct – Part I
struct – Part II
struct – Part III
Pointers – Part I
Pointers – Part II
interface – Part I
interface – Part II
interface – Part III
interface – Part IV
defer – Part I
defer – Part II
defer – Part III
defer – Part III
panic
panic and recover
panic, recover and defer
Getting started with GoLand IDE.
Getting started with GoLand IDE.
packages.
import packages – Part I.
import packages – Part II.
import packages – Part III.
goroutine – intro .
goroutines & panic.
Waiting for goroutines.
Waitgroup.
Play more with Waitgroup.
<- Channels ->.
Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Lockdown Learning – Day #47 – Channels in GoLang (Music Only)

By Prabhu Sunderaraman on May 11, 2020 in Go, Golang

Continuing with our lockdown learning of Go language. Here’s a video where we discussChannels in Golang

package main

import "fmt"

func main() {
	//Channels are pipelines used to communicate with goroutines

	//channel is used to pass and receive integer data
	var channel chan int
	fmt.Println(channel)

	//Initialized using make
	channel = make(chan int)
	fmt.Println(channel)

	//You can send data to a channel using <-
	channel <- 10

	//You can receive data from a channel using <-
	data := <- channel
	fmt.Println(data)

	//Send, receive operations are blocking
	//So you need to have a goroutine receiving and sending data
	//Let's discuss that in the next video :)
}


You can watch other videos in Go lang in the links below

Getting Started
Variables and Constants
Data types
Conditional statements
Loops
Arrays
Maps
Slices – I
Slices – II
range
Functions – Part I
Functions – Part II
Closures
types
Type Conversions
struct – Part I
struct – Part II
struct – Part III
Pointers – Part I
Pointers – Part II
interface – Part I
interface – Part II
interface – Part III
interface – Part IV
defer – Part I
defer – Part II
defer – Part III
defer – Part III
panic
panic and recover
panic, recover and defer
Getting started with GoLand IDE.
Getting started with GoLand IDE.
packages.
import packages – Part I.
import packages – Part II.
import packages – Part III.
goroutine – intro .
goroutines & panic.
Waiting for goroutines.
Waitgroup.
Play more with Waitgroup.
Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Lockdown Learning – Day #46– Play more with WaitGroup in GoLang (Music Only)

By Prabhu Sunderaraman on May 10, 2020 in Go, Golang

Continuing with our lockdown learning of Go language. Here’s a video where we Play more with WaitGroup in Golang

package main

import (
	"fmt"
	"sync"
)

func main() {
	wg := sync.WaitGroup{} //a structure
	fmt.Println(wg)

	wg.Add(1)
	//go doSomething(wg) //Passing a copy of waitgroup. So no modifications to the original
	go doSomething(&wg)
	
        //wg.Add(1) //Wait for 1 go routine to finish
	//wg.Add(2)//Wait for 2 go routines to finish. But we have only one GoRoutine. hmm
	//This delta: <number> is equal to the number of times Done() gets called from goroutines

	//go func() {
	//	fmt.Println("...Inside goroutine 1")
	//	wg.Done()
	//	wg.Done() //Silly isn't it?
	//	wg.Done()//panic: sync: negative WaitGroup counter
	//
	//}()
	wg.Wait()
	fmt.Println("****END")

}
func doSomething(wg *sync.WaitGroup)  {
	fmt.Println("...DoSomething")
	wg.Done()
}

You can watch other videos in Go lang in the links below

Getting Started
Variables and Constants
Data types
Conditional statements
Loops
Arrays
Maps
Slices – I
Slices – II
range
Functions – Part I
Functions – Part II
Closures
types
Type Conversions
struct – Part I
struct – Part II
struct – Part III
Pointers – Part I
Pointers – Part II
interface – Part I
interface – Part II
interface – Part III
interface – Part IV
defer – Part I
defer – Part II
defer – Part III
defer – Part III
panic
panic and recover
panic, recover and defer
Getting started with GoLand IDE.
Getting started with GoLand IDE.
packages.
import packages – Part I.
import packages – Part II.
import packages – Part III.
goroutine – intro .
goroutines & panic.
Waiting for goroutines.
Waitgroup.
Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Lockdown Learning – Day #45– WaitGroup & Goroutines in GoLang (Music Only)

By Prabhu Sunderaraman on May 9, 2020 in Go, Golang

Continuing with our lockdown learning of Go language. Here’s a video on WaitGroup in goroutines in Golang

A goroutine may have to wait for another goroutine to complete. Using time.Sleep() is a very crude way to wait. Here’s where WaitGroup comes to picture. This is similar to CountDownLatch in Java

package main

import (
	"fmt"
	"math/rand"
	"sync"
	"time"
)

func main() {
	//We need to ask main goroutine to wait for fixIssues() goroutine to complete its task
	wg := sync.WaitGroup{}
	wg.Add(1) //WaitGroup is like a countdown system. It will wait till the count is 1
	go fixIssues(&wg)

	//time.Sleep(time.Second * 5)//Not intuitive and correct too

	//Main go routine is waiting now
	//Blocking statement
	wg.Wait()
	fmt.Println("***Enough! I am done waiting")
}

func fixIssues(wg *sync.WaitGroup)  {
	defer wg.Done() //When the goroutine is completed, it sends a signal ie., it has completed for the lock to release
	i := 0
	rand.Seed(time.Now().UnixNano())
	iterations := rand.Intn(20)
	fmt.Println("Time required:", iterations, "seconds")
	for i < iterations {
		fmt.Println("Fixing Issues ...")
		time.Sleep(time.Second * 1)
		i++
	}

}

You can watch other videos in Go lang in the links below

Getting Started
Variables and Constants
Data types
Conditional statements
Loops
Arrays
Maps
Slices – I
Slices – II
range
Functions – Part I
Functions – Part II
Closures
types
Type Conversions
struct – Part I
struct – Part II
struct – Part III
Pointers – Part I
Pointers – Part II
interface – Part I
interface – Part II
interface – Part III
interface – Part IV
defer – Part I
defer – Part II
defer – Part III
defer – Part III
panic
panic and recover
panic, recover and defer
Getting started with GoLand IDE.
Getting started with GoLand IDE.
packages.
import packages – Part I.
import packages – Part II.
import packages – Part III.
goroutine – intro .
goroutines & panic.
Waiting for goroutines.
Share this on: Mixx Delicious Digg Facebook Twitter
1 2 … 64 Next »

Youtube Channel




Categories

  • JavaScript (48)
    • RequireJS (5)
  • Go (44)
  • Golang (44)
  • Ext JS (23)
  • Spring (22)
  • Mobile (21)
  • Scala (20)
    • Play (3)
  • Uncategorized (19)
  • Video Sessions (18)
  • GoG (17)
  • Sencha Touch (16)
  • jQuery (14)
  • Languages (13)
  • Java 8 (12)
  • React JS (11)
  • Kotlin (11)
  • HealthyCodeMagazine (9)
  • Video (9)
  • Objective-C (8)
  • NoSQL (8)
  • Android (7)
  • MongoDB (7)
  • GWT (6)
  • Tools (6)
  • HTML 5 (5)
  • Cloud (5)
  • General (5)
  • Micro services (5)
  • Java (5)
  • Books (4)
  • AWS (4)
  • Software Architecture (4)
  • .NET (3)
  • Elixir (3)
  • Docker (3)
  • Reactive (3)
  • NodeJS (2)
  • RoR (2)
  • Backbone (1)
  • AngularJS (1)

Archives

  • 2020 (49)
  • 2019 (7)
  • 2018 (34)
  • 2017 (15)
  • 2016 (7)
  • 2015 (18)
  • 2014 (31)
  • 2013 (55)
  • 2012 (100)

Search

Subscribe




Copyright © 2025 Prabhu Sunderaraman.

Powered by WordPress and News.