Go Learning Notes (2)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

    • Go language
      • Interface
      • Concurrent
        • Channel
        • Buffered Channels

Go language

Interface

A combination of a group of method

typeinterface {   SayHi()   string)}var i Meni = mike
    • As long as the struct that implements all the functions in interface can be assigned to I;
    • The function of the abstract base class in C + + can be realized by taking interface as the parameter of functions.
    • Value, OK = element. (T) upcasting;
    • Reflection T: = Reflect. Typeof (i)

Concurrent

Goroutine: Smaller-grained units than threads

go hello(a, b, c)
    • The Go keyword launches a goroutine
    • Goexit (defer function is still called)
    • Gosched (Give up CPU time)

Channel

Communication of Goroutine

make(chanint)ch <- v   # 把 v 发给 chv := <- ch  # 从 ch 收信
    • The assignment and reading values of the default ch are blocked;

Buffered Channels

CH: = Make (chan bool, 4)
* So the first four elements, do not block; The first element begins to block;
* range can be used to foreach Channel
* Close can show closed channel no longer receives message;
* Select (Linux-like Select);
* Select monitors multiple channels simultaneously;

copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.