{"id":35967,"date":"2022-05-23T15:26:35","date_gmt":"2022-05-23T19:26:35","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=35967"},"modified":"2022-05-24T14:54:40","modified_gmt":"2022-05-24T18:54:40","slug":"combines-collect-bytime-timer","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/05\/23\/combines-collect-bytime-timer\/","title":{"rendered":"Combine&rsquo;s .collect(.byTime) Timer"},"content":{"rendered":"<p><a href=\"https:\/\/www.hogbaysoftware.com\/posts\/combines-collect-by-time\/\">Jesse Grosjean<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.hogbaysoftware.com\/posts\/combines-collect-by-time\/\">\n<p>The biggest bug in Bike&rsquo;s 1.0 release was excessive CPU use while in background.<\/p>\n<p>[&#8230;]<\/p>\n<p>First, I didn&rsquo;t realize that each time you use <code>.collect(.byTime)<\/code> you are setting up a new repeating timer. I had expected a timer was involved, but thought it would only get scheduled when new items were coming into the publisher. Nope, it&rsquo;s repeating once the pipeline is setup.<\/p>\n<p>[&#8230;]<\/p>\n<p>I&rsquo;ve posted a <code>.collect(.byTime)<\/code> <a href=\"https:\/\/forums.swift.org\/t\/combines-collect-bytime-schedules-a-repeating-timer\/57456\/2\">replacement<\/a> (for my use case) here. It solves the problem by only scheduling on the runloop once per group of incoming results.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/05\/17\/bike-1-0\/\">Bike 1.0<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/03\/28\/swift-async-algorithms-package\/\">Swift &ldquo;Async Algorithms&rdquo; Package<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Jesse Grosjean: The biggest bug in Bike&rsquo;s 1.0 release was excessive CPU use while in background. [&#8230;] First, I didn&rsquo;t realize that each time you use .collect(.byTime) you are setting up a new repeating timer. I had expected a timer was involved, but thought it would only get scheduled when new items were coming into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-05-23T19:26:38Z","apple_news_api_id":"04b4125e-f6dc-4c45-8527-85db79ced68b","apple_news_api_modified_at":"2022-05-24T18:54:43Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/ABLQSXvbcTEWFJ4Xbec7Wiw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[2206,131,1813,30,2077,74,138,71,901],"class_list":["post-35967","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bike","tag-bug","tag-combine-framework","tag-mac","tag-macos-12","tag-opensource","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=35967"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35967\/revisions"}],"predecessor-version":[{"id":35968,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35967\/revisions\/35968"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=35967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=35967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=35967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}