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

Is there any Flag to check data successfully written to channel? #3

Closed
yogihardi opened this issue Nov 23, 2017 · 2 comments
Closed

Comments

@yogihardi
Copy link

Hi,

we are using this lib to do long polling for our REST API, but we facing issue when sending data to our API, it seems the channel not blocked and not waits till data written to a variable, so we don't know when it's finished or not, please check following code for details:

	for {
		datach, err := c.pollChannel.Get(poll.PollTime) // this line will get data from longpoll
		if err != nil {
			break
		}
		rows := <-datach // get data from channel
		logrus.Debugf("from poll channel: %d", rows) // this debug will print data from channel (data exists)
		if (rows != nil){
                    // processing the data and pass it to API 
                }
      }

// return data empty to API
// in our case, we always got empty data even though debug prints the data to console. 

our question: Is there any Flag to check the go routine / channel are done? so, we can tells API to waits and response if data ready.

@osklyar
Copy link
Collaborator

osklyar commented Nov 23, 2017

I am sorry I do not understand "we always got empty data even though debug prints the data to console": it is not clear in which line of this code sample you get no data which is earlier printed by the debug. Fact is, if the debug prints data correctly, then the library functions as designed as the library is about waiting for data and getting it out, not about what happens to it afterwards.

I also do not quite understand what sort of flag you want. Long polling works like this: you wait for data on a channel, if data arrives then the polling channel immediately returns with that data in a go channel. If the data does not arrive, the polling channel also returns, but after the timeout and with an empty go channel. There is no flag to indicate one of the other. Furthermore, you always get something in the Go channel after the polling period completes (with or without data), just what you get is different. If I recall right, you either get and empty slice or a slice with data, but please check tests as I did not touch the lib for a long time now.

@yogihardi
Copy link
Author

Hi,

Thank you for the answer.

if data arrives then the polling channel immediately returns with that data in a go channel. If the data does not arrive, the polling channel also returns, but after the timeout and with an empty go channel

it's clear now for me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants