{"action":"created","issue":{"url":"https://api.github.com/repos/xluohome/smscode/issues/2","repository_url":"https://api.github.com/repos/xluohome/smscode","labels_url":"https://api.github.com/repos/xluohome/smscode/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/xluohome/smscode/issues/2/comments","events_url":"https://api.github.com/repos/xluohome/smscode/issues/2/events","html_url":"https://github.com/xluohome/smscode/issues/2","id":274723563,"number":2,"title":"only once request, but server will do more than once request.","user":{"login":"docooler","id":3860625,"avatar_url":"https://avatars1.githubusercontent.com/u/3860625?v=4","gravatar_id":"","url":"https://api.github.com/users/docooler","html_url":"https://github.com/docooler","followers_url":"https://api.github.com/users/docooler/followers","following_url":"https://api.github.com/users/docooler/following{/other_user}","gists_url":"https://api.github.com/users/docooler/gists{/gist_id}","starred_url":"https://api.github.com/users/docooler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docooler/subscriptions","organizations_url":"https://api.github.com/users/docooler/orgs","repos_url":"https://api.github.com/users/docooler/repos","events_url":"https://api.github.com/users/docooler/events{/privacy}","received_events_url":"https://api.github.com/users/docooler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-17T01:38:17Z","updated_at":"2017-11-19T14:21:58Z","closed_at":null,"author_association":"NONE","body":"写的这个工具相当实用，我也学习了下源码。不过看起来只有一次请求，但是手机可能会收到多条信息。\r\napiserver.go 里面的case api.req[hash] <- req:会不停的给worker发请求。虽然我们只需要一次。我没有运行过这个代码，不过从代码review上来说是会发送多次请求给worker。下面我写了个简单模型：\r\npackage main\r\n\r\nimport (\r\n\t\t\"log\"\r\n\t\t\"time\"\r\n\t\t\"math/rand\"\r\n\t\t)\r\n\r\nfunc  main() {\r\n\tch1 := make(chan int)\r\n\tch2 := make(chan int)\r\n\r\n\tgo func () {\r\n\t\tfor a := range ch1 {\r\n\t\t\t<-time.After(5)\r\n\t\t\tch2 <-a\r\n\t\t}\r\n\t}()\r\n\td := rand.Intn(100)\r\n\tfor  {\r\n\t\tselect {\r\n\t\tcase ch1 <- d:\r\n\t\tcase  a := <-ch2:\r\n\t\t\tlog.Println(\"get a = \", a)\r\n\t\t\t// return\r\n\t\tcase <-time.After(time.Second):\r\n\t\t\tlog.Println(\"time out 1000\")\r\n\r\n\t\t}\r\n\t}\r\n}\r\n\r\n我们运行以后可以看到：\r\nlog.Println(\"get a = \", a)执行了很多遍，说明worker一直在执行这个请求（也就是发送了多条信息）。只是这个代码里面加了return所以只care第一条。我觉得应该把 api.req[hash] <- req放到for循环外。"},"comment":{"url":"https://api.github.com/repos/xluohome/smscode/issues/comments/345520330","html_url":"https://github.com/xluohome/smscode/issues/2#issuecomment-345520330","issue_url":"https://api.github.com/repos/xluohome/smscode/issues/2","id":345520330,"user":{"login":"xluohome","id":20061705,"avatar_url":"https://avatars1.githubusercontent.com/u/20061705?v=4","gravatar_id":"","url":"https://api.github.com/users/xluohome","html_url":"https://github.com/xluohome","followers_url":"https://api.github.com/users/xluohome/followers","following_url":"https://api.github.com/users/xluohome/following{/other_user}","gists_url":"https://api.github.com/users/xluohome/gists{/gist_id}","starred_url":"https://api.github.com/users/xluohome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xluohome/subscriptions","organizations_url":"https://api.github.com/users/xluohome/orgs","repos_url":"https://api.github.com/users/xluohome/repos","events_url":"https://api.github.com/users/xluohome/events{/privacy}","received_events_url":"https://api.github.com/users/xluohome/received_events","type":"User","site_admin":false},"created_at":"2017-11-19T14:21:57Z","updated_at":"2017-11-19T14:21:57Z","author_association":"OWNER","body":"非常感谢提交pr；\r\n\r\n您写的demo 与smscode中的 for select 有相似用法。但smscode中的这个for 循环不会超过2次以上：第一次循环是输入数据到req[hash] chan ,第二次循环是等待 resultchan chan到来或者超时chan 的触发；\r\n且这两个chan 是一对一的，保证了在并发时的安全。 所以不存在您说的会发送多次手机验证码的情况发生（收到多个验证码）。\r\n\r\n另为 ，为什么要用这种方式实现，我当时考虑到即要提高并发处理量但又要限制单个手机号的并发量，简单说就是要限制同一个手机号API请求是顺序同步的，这样可以做一些单号码的发送限制；\r\n\r\n不知我上面的回复是否对您有帮助？\r\n\r\n谢谢；\r\n\r\n> 在 2017年11月17日，09:38，docooler <notifications@github.com> 写道：\r\n> \r\n> 写的这个工具相当实用，我也学习了下源码。不过看起来只有一次请求，但是手机可能会收到多条信息。\r\n> apiserver.go 里面的case api.req[hash] <- req:会不停的给worker发请求。虽然我们只需要一次。我没有运行过这个代码，不过从代码review上来说是会发送多次请求给worker。下面我写了个简单模型：\r\n> package main\r\n> \r\n> import (\r\n> \"log\"\r\n> \"time\"\r\n> \"math/rand\"\r\n> )\r\n> \r\n> func main() {\r\n> ch1 := make(chan int)\r\n> ch2 := make(chan int)\r\n> \r\n> go func () {\r\n> \tfor a := range ch1 {\r\n> \t\t<-time.After(5)\r\n> \t\tch2 <-a\r\n> \t}\r\n> }()\r\n> d := rand.Intn(100)\r\n> for  {\r\n> \tselect {\r\n> \tcase ch1 <- d:\r\n> \tcase  a := <-ch2:\r\n> \t\tlog.Println(\"get a = \", a)\r\n> \t\t// return\r\n> \tcase <-time.After(time.Second):\r\n> \t\tlog.Println(\"time out 1000\")\r\n> \r\n> \t}\r\n> }\r\n> }\r\n> \r\n> 我们运行以后可以看到：\r\n> log.Println(\"get a = \", a)执行了很多遍，说明worker一直在执行这个请求（也就是发送了多条信息）。只是这个代码里面加了return所以只care第一条。我觉得应该把 api.req[hash] <- req放到for循环外。\r\n> \r\n> —\r\n> You are receiving this because you are subscribed to this thread.\r\n> Reply to this email directly, view it on GitHub, or mute the thread.\r\n> \r\n"}}
{"actor":{"display_login":"xluohome"}}