From e14743d3719c89a2c96213e07d8b8747df8fc633 Mon Sep 17 00:00:00 2001 From: Sergei Stadnik Date: Sun, 24 May 2020 14:18:18 -0700 Subject: [PATCH 1/2] Add channel.md, channel-operators.md --- channel-operators.md | 63 ++++++++++++++++++++++++++++++++++++++++ channel.md | 49 +++++++++++++++++++++++++++++++ pull_request_template.md | 42 --------------------------- 3 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 channel-operators.md create mode 100644 channel.md delete mode 100644 pull_request_template.md diff --git a/channel-operators.md b/channel-operators.md new file mode 100644 index 0000000..640beed --- /dev/null +++ b/channel-operators.md @@ -0,0 +1,63 @@ +--- +layout: default +--- + +# Channel operators: Send and Receive + +Example demonstrates send and receive channel operators in Go programming language. Channel works with two principal operations, one is sending and another one is receiving. +The direction of `<-` operator indicates whether the data is received or send. + +Click [here](https://tour.golang.org/concurrency/2) to learn more + +```go +/* +* Send operation is used to send data from one goroutine to another with the help of a channel. Values like int, float64, and bool can be safely send through a channel because * they are copied, and there is no risk of accidental concurrent access of the same value. Similarly, strings are also safe to transfer because they are immutable. But sending +* pointers or reference like a slice, map, etc. through a channel are not safe because the value of pointers or reference may change by sending goroutine or by the receiving +* goroutine at the same time and the result is unpredicted. So, when you use pointers or references in the channel you must make sure that they can only access by the ONE goroutine * at a time. For example, *Mychannel <- element* indicates that the data(element) SEND to the channel(Mychannel) with the help of a <- operator. +*/ + +/* +* The receive operation is used to receive the data sent by the send operator. +* Here, *element := <-Mychannel* indicates that the element RECEIVES data from the channel(Mychannel). +* You can also write a receive statement as: *<-My channel* +*/ + +package main + +import "fmt" + +func myfunc(ch chan int) { + + fmt.Println(234 + <-ch) +} +func main() { + fmt.Println("start Main method") + // Creating a channel + ch := make(chan int) + + go myfunc(ch) + ch <- 23 + fmt.Println("End Main method") +} + +``` +### Output + +```bash +start Main method +257 +End Main method +``` + + +Try It Out | Source Code + +### Contributors +- Sagar Jadhav + +[<< Home Page](./) | [Previous << ](./.html) | [Next >> ](./.html) + + + + + diff --git a/channel.md b/channel.md new file mode 100644 index 0000000..ac91b38 --- /dev/null +++ b/channel.md @@ -0,0 +1,49 @@ +--- +layout: default +--- + +# Channel + +Example demonstrates creating channel in Go programming language. Channel is a medium through which a goroutine communicates with another goroutine. +By default, channel is bidirectional, it can only transfer data of the same type. +Click [here](https://tour.golang.org/concurrency/2) to learn more + +```go +/* + * A channel is created using chan keyword. + * You can also create a channel using make() function using a shorthand declaration. + */ +package main + +import "fmt" + +func main() { + + // Creating a channel + // Using var keyword + var mychannel chan int + fmt.Println("Value of the channel: ", mychannel) + fmt.Printf("Type of the channel: %T ", mychannel) + + // Creating a channel using make() function + mychannel1 := make(chan int) + fmt.Println("\nValue of the channel1: ", mychannel1) + fmt.Printf("Type of the channel1: %T ", mychannel1) +} + +``` +### Output + +```bash +Value of the channel: +Type of the channel: chan int +Value of the channel1: 0x432080 +Type of the channel1: chan int +``` + +Try It Out | Source Code + +### Contributors +- Sagar Jadhav + +[<< Home Page](./) | [Previous << ](./.html) | [Next >> ](./.html) diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index a34cb8a..0000000 --- a/pull_request_template.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -layout: default ---- - -Fixes # (issue) - -## Type of change - -Please delete options that are not relevant. - -- Bug fix (non-breaking change which fixes an issue) -- New feature (non-breaking change which adds functionality) -- Breaking change (fix or feature that would cause existing functionality to not work as expected) -- This change requires a documentation update - -## How Has This Been Tested? - - - -**Test Configuration** -* Firmware version -* Hardware -* Toolchain -* SDK - -## Checklist: - -- My code follows the style guidelines of this project -- I have performed a self-review of my own code -- I have commented my code, particularly in hard-to-understand areas -- I have made corresponding changes to the documentation -- My changes generate no new warnings -- I have added tests that prove my fix is effective or that my feature works -- New and existing unit tests pass locally with my changes -- Any dependent changes have been merged and published in downstream modules - -[<< Back](./) \ No newline at end of file From bada78f4f570e39f69618a23672090f8fe63eca6 Mon Sep 17 00:00:00 2001 From: Sergei Stadnik Date: Sun, 24 May 2020 14:19:52 -0700 Subject: [PATCH 2/2] Update pull_request_template.md --- pull_request_template.md | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..8fa116d --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,46 @@ +--- +layout: default +--- + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- New feature (non-breaking change which adds functionality) + Added channel.md and channel-operators.md + + +## How Has This Been Tested? + + +Tested to the best of my knowledge +-in Github +-on GoPlayground + +**Test Configuration** +* Firmware version +* Hardware +* Toolchain +* SDK + +-Win 10 Pro + +## Checklist: + +- My code follows the style guidelines of this project +- I have performed a self-review of my own code +- I have commented my code, particularly in hard-to-understand areas +- I have made corresponding changes to the documentation +- My changes generate no new warnings +- I have added tests that prove my fix is effective or that my feature works +- New and existing unit tests pass locally with my changes +- Any dependent changes have been merged and published in downstream modules + +[<< Back](./) \ No newline at end of file