{"action":"closed","issue":{"url":"https://api.github.com/repos/ibireme/YYAsyncLayer/issues/6","repository_url":"https://api.github.com/repos/ibireme/YYAsyncLayer","labels_url":"https://api.github.com/repos/ibireme/YYAsyncLayer/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/ibireme/YYAsyncLayer/issues/6/comments","events_url":"https://api.github.com/repos/ibireme/YYAsyncLayer/issues/6/events","html_url":"https://github.com/ibireme/YYAsyncLayer/issues/6","id":158505575,"number":6,"title":"请教一个关于计数器 YYSentinel 的问题","user":{"login":"KittenYang","id":5517281,"avatar_url":"https://avatars.githubusercontent.com/u/5517281?v=3","gravatar_id":"","url":"https://api.github.com/users/KittenYang","html_url":"https://github.com/KittenYang","followers_url":"https://api.github.com/users/KittenYang/followers","following_url":"https://api.github.com/users/KittenYang/following{/other_user}","gists_url":"https://api.github.com/users/KittenYang/gists{/gist_id}","starred_url":"https://api.github.com/users/KittenYang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KittenYang/subscriptions","organizations_url":"https://api.github.com/users/KittenYang/orgs","repos_url":"https://api.github.com/users/KittenYang/repos","events_url":"https://api.github.com/users/KittenYang/events{/privacy}","received_events_url":"https://api.github.com/users/KittenYang/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-06-04T13:48:24Z","updated_at":"2016-06-05T06:33:59Z","closed_at":"2016-06-05T06:33:58Z","body":"在看源码的过程中，对及时退出绘制任务的实现方案的理解有点拿不准，特来求证一下。\r\n首先我一直很好奇，什么时候会 `value != sentinel.value;`，换言之，得滑到多快，才能让 `value != sentinel.value;`？\r\n\r\n源码里面，只要 cell 出现在屏幕上，都会触发一次 `setNeedsDisplay`:\r\n```objc\r\n- (void)setNeedsDisplay {\r\n    [self _cancelAsyncDisplay]; //1\r\n    [super setNeedsDisplay]; //2\r\n}\r\n```\r\n这里面，//1 处会让计数器加1，我们可以把它认为是标准值；//2 里面会做一次取值：\r\n```objc\r\nYYSentinel *sentinel = _sentinel;\r\nint32_t value = sentinel.value; //3\r\n```\r\n而由于 1、2 操作都是在主线程做的，所以会按先后顺序来。\r\n\r\n所以，我的结论就是，源码中只是利用了函数调用的时间差，也就是说，只有当滑动的速度比 1、3 两处函数调用的时间差还要快，才会触发 `isCancelled` 判断条件。\r\n\r\n以上是我的理解，不知道是否正确，特来求证，望指教。\r\n\r\nPS：另外，还有一点想法，源码中的 `isCancelled` 属于主动式获取，必须去调用才知道是否不一致了，不太精准，容易漏掉。有没有可能实现被动式通知，就是一旦触发 `value != sentinel.value;` 就通知线程退出呢？"}}
{"actor":{"display_login":"KittenYang"}}