Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sergei #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions channel-operators.md
Original file line number Diff line number Diff line change
@@ -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
```


<a href='https://play.golang.org/p/B-54vzrROU3' target='_blank'>Try It Out</a> | <a href='' target='_blank'>Source Code</a>

### Contributors
- <a href='https://github.com/sagar-jadhav' target='_blank'>Sagar Jadhav</a>

[<< Home Page](./) | [Previous << ](./.html) | [Next >> ](./.html)





49 changes: 49 additions & 0 deletions channel.md
Original file line number Diff line number Diff line change
@@ -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
```

<a href='https://play.golang.org/p/HjmlW1VVynF' target='_blank'>Try It Out</a> | <a href='' target='_blank'>Source Code</a>

### Contributors
- <a href='https://github.com/sagar-jadhav' target='_blank'>Sagar Jadhav</a>

[<< Home Page](./) | [Previous << ](./.html) | [Next >> ](./.html)
10 changes: 7 additions & 3 deletions pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ Fixes # (issue)

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
Added channel.md and channel-operators.md


## How Has This Been Tested?

Expand All @@ -21,13 +20,18 @@ Please also list any relevant details for your test configuration

- Test A
- Test B -->
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
Expand Down