Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:31:43+00:00 2026-06-13T06:31:43+00:00

Using a buffered channel, how do measure how many elements are in the channel?

  • 0

Using a buffered channel, how do measure how many elements are in the channel? For example, I’m creating and sending on a channel like this:

send_ch := make(chan []byte, 100)
// code
send_ch <- msg

I want to measure how many msgs are in the channel send_ch.

I’m aware that due to concurrency the measurement won’t be exact, as pre-emption could occur between measurement and action (eg discussed in this video Google I/O 2012 – Go Concurrency Patterns). I’ll be using this for flow control between producers and consumers ie once I’ve passed through a high watermark, changing some behaviour until I pass back through a low watermark.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:31:44+00:00Added an answer on June 13, 2026 at 6:31 am

    http://golang.org/pkg/builtin/#len

    func len(v Type) int
    The len built-in function returns the length of v, according to its type:

    • Array: the number of elements in v.
    • Pointer to array: the number of elements in *v (even if v is nil).
    • Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
    • String: the number of bytes in v.
    • Channel: the number of elements queued (unread) in the channel buffer; if v is nil, len(v) is zero.
    package main
    
    import "fmt"
    
    func main() {
            c := make(chan int, 100)
            for i := 0; i < 34; i++ {
                    c <- 0
            }
            fmt.Println(len(c))
    }
    

    will output:

    34
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started using the audio elements buffered attribute. I have only tested
I have a while loop that adds elements read using a Buffered Reader to
With an example like this. How can I do 2d double buffering with gtk
I'm creating piecharts using JFreeChart , use chart.createBufferedImage(width,height) and give the buffered image to
Hi I have been using the Buffered Reader to try to read a text
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
i Had load my image Buffered image now need to brighten it using Slider
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.