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

  • SEARCH
  • Home
  • 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 7067603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:20+00:00 2026-05-28T05:13:20+00:00

Suppose I’m parsing some kind of input with the following three methods: func parseHeader

  • 0

Suppose I’m parsing some kind of input with the following three methods:

func parseHeader ([]byte) []byte
func parseBody   ([]byte) []byte
func parseFooter ([]byte) []byte

They all parse a certain part of the same input and return it as []byte, so they can be used like this:

i := []byte( /* the input */ )
b := new(bytes.Buffer)

b.Write(parseHeader(i))
b.Write(parseBody(i))
b.Write(parseFooter(i))

Now I’d like to make these 3 processes parallel by using channels. My idea was passing a channel to these functions for them to write to, but how can I make sure they will write in the correct order to the channel? (i.e. that the body is written to the channel after the header and the footer after the body)

  • 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-05-28T05:13:21+00:00Added an answer on May 28, 2026 at 5:13 am

    Essentially you can’t, at least not without adding an additional layer of messages to do extra hand-shaking. What would be better to do is to use three separate channels and read from them in the order you want to receive them, that way you don’t need to worry about the write-order of the sending processes.

    Here’s a minimal example:

    package main
    
    import "fmt"
    
    func sendme(num int, ch chan int) {
            ch <- num // send integer 'num' down chan ch
    }
    
    func main() {
            // Create three new channels
            one := make(chan int)
            two := make(chan int)
            three := make(chan int)
    
            // Start each parallel invocation of "sendme" as a go routine, in any order
            go sendme(3, three)
            go sendme(1, one)
            go sendme(2, two)
    
            // Read from each channel in the order we wish to process the
            // data
            fmt.Println(<- one, <- two, <- three)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following HTML snippet: <input type=text id=myinput /> Now I want
Suppose , i have some x test-cases to be read from input, where each
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
Suppose I have the following CSS rule in my page: body { font-family: Calibri,
Suppose the following: >>> s = set([1, 2, 3]) How do I get a
suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
Suppose the following constructor: class Needed { public: Needed () {} Needed (const char
Suppose we have the following: data Foo x from_list :: [x] -> Foo x
Suppose I have the following table: PERSON : ID INT NAME STRING LASTNAME STRING
Suppose a mysql 5.5 server uses the following configuration for storing innodb data innodb_data_file_path

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.