{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/611","repository_url":"https://api.github.com/repos/ReactiveX/RxSwift","labels_url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/611/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/611/comments","events_url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/611/events","html_url":"https://github.com/ReactiveX/RxSwift/issues/611","id":147260242,"number":611,"title":"takeUntil canceling before next event","user":{"login":"rodrigoruiz","id":764094,"avatar_url":"https://avatars.githubusercontent.com/u/764094?v=3","gravatar_id":"","url":"https://api.github.com/users/rodrigoruiz","html_url":"https://github.com/rodrigoruiz","followers_url":"https://api.github.com/users/rodrigoruiz/followers","following_url":"https://api.github.com/users/rodrigoruiz/following{/other_user}","gists_url":"https://api.github.com/users/rodrigoruiz/gists{/gist_id}","starred_url":"https://api.github.com/users/rodrigoruiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rodrigoruiz/subscriptions","organizations_url":"https://api.github.com/users/rodrigoruiz/orgs","repos_url":"https://api.github.com/users/rodrigoruiz/repos","events_url":"https://api.github.com/users/rodrigoruiz/events{/privacy}","received_events_url":"https://api.github.com/users/rodrigoruiz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-10T20:07:23Z","updated_at":"2016-04-16T08:37:19Z","closed_at":"2016-04-16T08:37:19Z","body":"Following a similar example to question 39 here: http://reactivex.io/learnrx/\r\n\r\nI'm trying to transforma a method call \"search(query: String)\" into a sequence of those calls.\r\nThey way I'm achieving this is by creating a \"Variable\" which I update with the \"query\" value every time \r\nthe \"search(query: String)\" method is called.\r\n\r\nThen I have this in my \"init()\":\r\n`_ = queryVariable.asObservable().flatMap({ query -> Observable<[JSON]> in\r\n    return self.facebookSearch(query).takeUntil(self.queryVariable.asObservable())\r\n}).subscribeNext({ result in\r\n    if let name = result[0][\"name\"].string {\r\n        print(name)\r\n    } else {\r\n        print(\"problem\")\r\n    }\r\n})`\r\n\r\nIf I type \"ABC\", my \"search(query: String)\" method will be called 3 times with \"A\", \"AB\", \"ABC\".\r\nThat would be mapped to seq([\"A\", \"AB\", \"ABC\"]) with \"queryVariable.asObservable()\".\r\nThen I'm mapping it to facebook searches (searching people by their names on Facebook).\r\nAnd with \"subscribeNext\" I print the name.\r\nIf I don't use the \"takeUntil\", it works as I'd expect, I get 3 sets of results, one for each of my queries(\"A\", \"AB\", \"ABC\").\r\n\r\nBut if I type fast (before Facebook has time to responde to the request), I'd want only one result, for the query \"ABC\". That's why I added the \"takeUntil\". With it I'd expect the \"facebookSearch(query: String)\" call to be ignored when the next \"query\" comes in, but it is being canceled for the current query, so with this \"takeUntil\" I end up printing nothing.\r\n\r\nIs this a known issue or am I doing something wrong?"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/comments/210770555","html_url":"https://github.com/ReactiveX/RxSwift/issues/611#issuecomment-210770555","issue_url":"https://api.github.com/repos/ReactiveX/RxSwift/issues/611","id":210770555,"user":{"login":"kzaher","id":1641148,"avatar_url":"https://avatars.githubusercontent.com/u/1641148?v=3","gravatar_id":"","url":"https://api.github.com/users/kzaher","html_url":"https://github.com/kzaher","followers_url":"https://api.github.com/users/kzaher/followers","following_url":"https://api.github.com/users/kzaher/following{/other_user}","gists_url":"https://api.github.com/users/kzaher/gists{/gist_id}","starred_url":"https://api.github.com/users/kzaher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzaher/subscriptions","organizations_url":"https://api.github.com/users/kzaher/orgs","repos_url":"https://api.github.com/users/kzaher/repos","events_url":"https://api.github.com/users/kzaher/events{/privacy}","received_events_url":"https://api.github.com/users/kzaher/received_events","type":"User","site_admin":false},"created_at":"2016-04-16T08:37:19Z","updated_at":"2016-04-16T08:37:19Z","body":"Oh, so I've forgot to answer the original question. There is no issue with takeUntil, variable will emit the initial value immediatelly, and that will cancel your request :)\r\n\r\nYeah, please take a look at flatMapLatest. I guess we should be able to close this one. We can reopen it if you have any followup questions. "}}