Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.07k stars 492 forks source link

problems with the code when sending #279

Open artem-webdev opened 4 years ago

artem-webdev commented 4 years ago

hi everyone, can anyone explain how to handle this correctly

https://github.com/Rhymen/go-whatsapp/blob/1a11f6d7ef42d3cc182985285b2ae9a0e7b3f71a/message.go#L89

is it just a trick to get out of the select?

maybe the message sending time has not expired, but the message status response time has expired ?

abnt713 commented 4 years ago

Actually this line of code avoids deadlocks. You can read more about channel selects here https://tour.golang.org/concurrency/, but basically the first channel to be ready executes the case block, the other(s) case block(s) is/are ignored. Unfortunately that doesn't mean the "send message" request was cancelled, meaning that even when the timeout is reached, the app can still send a message after some time. When a timeout happens, the safest bet would be verify manually if the message has been sent. History checking and local cache would help

artem-webdev commented 4 years ago

Thanks for the answer, but the question was not about the timer, the question is why this is not a warning but an error, and in fact there is no point in processing it, it’s more sense if you ignore it. Messages are still delivered! In general, there is more than one such place in the code, I just don’t understand whether this can be fixed or is it a delay from whatsapp api?

artem-webdev commented 4 years ago

for example here https://github.com/Rhymen/go-whatsapp/blob/1a11f6d7ef42d3cc182985285b2ae9a0e7b3f71a/contact.go#L58 or here https://github.com/Rhymen/go-whatsapp/blob/1a11f6d7ef42d3cc182985285b2ae9a0e7b3f71a/contact.go#L89

perhaps you can still find problem areas where returns <-chan

andig commented 4 years ago

hi everyone, can anyone explain how to handle this correctly

It's just the send timeout. If no response was read during wac.msgTimeout, the operation is timed out and the for loop broken.

perhaps you can still find problem areas where returns <-chan

@artem-webdev what problem is exactly are you trying to solve here? Return channels in go is not a "problem area"?

andig commented 4 years ago

In general, there is more than one such place in the code, I just don’t understand whether this can be fixed or is it a delay from whatsapp api?

The logic is simple: if you send a message, you should receive an answer. If not something went wrong.

Why you don't get an answer is another question, also discussed in https://github.com/Rhymen/go-whatsapp/issues/410.