{"id":474768,"date":"2025-09-12T15:00:26","date_gmt":"2025-09-12T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=474768"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=474768","title":{"rendered":"<span>Swift Concurrency \u0438 CoreBluetooth: \u043a\u0430\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 BLE-\u0441\u0435\u0440\u0432\u0438\u0441<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/67a\/ff7\/68c\/67aff768c5212129208b70fd0b99f818.png\" width=\"3116\" height=\"1766\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/67a\/ff7\/68c\/67aff768c5212129208b70fd0b99f818.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/67a\/ff7\/68c\/67aff768c5212129208b70fd0b99f818.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435: \u0432\u044b \u043f\u0440\u0438\u043b\u0435\u0442\u0430\u0435\u0442\u0435 \u0432 \u0430\u044d\u0440\u043e\u043f\u043e\u0440\u0442, \u0431\u0440\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c \u043a\u0430\u0440\u0448\u0435\u0440\u0438\u043d\u0433\u0430, \u043d\u043e \u0430\u0432\u0442\u043e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u0440\u043a\u043e\u0432\u043a\u0435. \u0423 \u0432\u0430\u0448\u0435\u0433\u043e iPhone \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0435\u0441\u0442\u044c, \u043d\u043e \u0443 \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0432\u044f\u0437\u0438 \u043d\u0435\u0442 \u2014 \u043e\u043d\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043a\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0430\u0432\u0442\u043e?<\/p>\n<p>\u041d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0441\u0435\u0442\u044c\u044e \u0432 \u0421\u0438\u0442\u0438\u0434\u0440\u0430\u0439\u0432\u0435 \u0435\u0441\u0442\u044c \u043e\u0444\u0444\u043b\u0430\u0439\u043d-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0432\u0435\u0440\u044c\u043c\u0438 \u043c\u0430\u0448\u0438\u043d\u044b \u0447\u0435\u0440\u0435\u0437 Bluetooth. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0431\u043b\u043e\u043a\u0435 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u0441 \u043d\u0438\u043c iPhone \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u0432\u0435\u0440\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u00ab\u043e\u0442\u0440\u0435\u0437\u0430\u043d\u0430\u00bb \u043e\u0442 \u0441\u0435\u0442\u0438. \u0422\u0430\u043a, Bluetooth \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0432\u0442\u043e \u0432 \u043b\u044e\u0431\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.<\/p>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0438. \u042f \u0432\u0437\u044f\u043b \u043d\u0430 \u0441\u0435\u0431\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u043e iOS \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 <code>Swift Concurrency<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 \u0441\u0442\u0430\u0440\u043e\u0433\u043e <code>CoreBluetooth<\/code>. \u041a\u0430\u043a \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a 20 000 \u043c\u0430\u0448\u0438\u043d \u0447\u0435\u0440\u0435\u0437 Bluetooth <a href=\"https:\/\/habr.com\/ru\/companies\/citydrive\/articles\/943792\/\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u043e\u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u0432\u044b\u043b\u0435\u0437\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0438 structured concurrency \u0438 callback-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e API, \u043a\u0430\u043a \u0438\u0445 \u043e\u0431\u043e\u0439\u0442\u0438 \u0438 \u043d\u0430 \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0442\u043e\u0436\u0435 \u0440\u0435\u0448\u0438\u0442\u0435 \u00ab\u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c\u00bb \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 async\/await \u043a \u0441\u0442\u0430\u0440\u043e\u043c\u0443 API.<\/p>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0430\u0432\u0442\u043e?<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3e2\/870\/151\/3e287015131eab53b1e157859dd0b243.png\" alt=\"\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430\" title=\"\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430\" width=\"1056\" height=\"822\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/3e2\/870\/151\/3e287015131eab53b1e157859dd0b243.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3e2\/870\/151\/3e287015131eab53b1e157859dd0b243.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044e \u0441 iPhone \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \u041c\u043e\u0434\u0443\u043b\u044c \u0440\u0430\u0437 \u0432 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435. \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <em>\u0442\u0440\u0443\u0431\u0443<\/em>, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u2014 \u043e\u043d \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0434\u043d\u0435\u0435. \u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043c\u043e\u0434\u0443\u043b\u044c, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u0440\u0438\u0434\u0451\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: \u0443\u0441\u043f\u0435\u0445, \u0441\u0442\u0430\u0442\u0443\u0441 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u043e\u0434\u0443\u043b\u044c \u2014 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0442\u0440\u0443\u0431\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u044b\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u044b.<\/p>\n<h2>CoreBluetooth <\/h2>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 BLE \u0432 iOS \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <a href=\"https:\/\/developer.apple.com\/documentation\/corebluetooth\" rel=\"noopener noreferrer nofollow\">\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <code>CoreBluetooth<\/code><\/a>. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u0430 \u0434\u0435\u043b\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430. \u0421 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044f: \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0442\u0430\u0442\u0443\u0441\u044b \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p><strong>\u0412\u043e\u0442 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/strong><\/p>\n<p><em>CBCentralManagerDelegate<\/em><\/p>\n<pre><code class=\"swift\">\/\/ \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 Bluetooth \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 func centralManagerDidUpdateState(_ central: CBCentralManager)  \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e BLE-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func centralManager(... didDiscover peripheral ...)  \/\/ \u0421\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443 func centralManager(... didConnect peripheral ...)<\/code><\/pre>\n<p><em>CBPeripheralDelegate<\/em><\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func peripheral(... didUpdateValueFor characteristic ...)  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func peripheral(... didDiscoverServices error ...)  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 func peripheral(... didDiscoverCharacteristicsFor service ...) <\/code><\/pre>\n<p>\u0410 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>CBCentralManager<\/code>. \u0412\u0441\u0451 \u044d\u0442\u043e \u044f \u0432\u044b\u043d\u0435\u0441 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 BLE \u0438 \u043d\u0435 \u0440\u0430\u0437\u043c\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043f\u043e \u043a\u043e\u0434\u0443. \u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430: \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0438\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 <code>didUpdateValueFor<\/code>.<\/p>\n<h2>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443<\/h2>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0430 <strong>Swift 6<\/strong>, \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430 \u2014 <code>Swift Concurrency<\/code> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 <code>strict mode<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 Bluetooth \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u044f\u0437\u044b\u043a\u0430, \u043d\u043e \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a callback\u2019\u0430\u043c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d <code>actor.<\/code> \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"swift\">protocol BluetoothServiceProtocol {  func connect() async throws  func disconnect() async  func write(_ message: String) async throws }  actor BluetoothService: BluetoothServiceProtocol<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <code>connect()<\/code> \u2014 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/strong> \u0432 \u043c\u043e\u0434\u0443\u043b\u0435. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0438 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043c\u043e\u0434\u0443\u043b\u044c, \u0434\u0430\u043b\u0435\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c. <strong>\u0422\u043e\u043b\u044c\u043a\u043e<\/strong> \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 <code>connect()<\/code>. \u0415\u0449\u0451 \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u2014 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c <code>timeout<\/code>.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/366\/039\/3c3\/3660393c319edf2c4ee19d2b1091b2fe.png\" alt=\"\u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 connect\" title=\"\u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 connect\" width=\"1600\" height=\"1226\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/366\/039\/3c3\/3660393c319edf2c4ee19d2b1091b2fe.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/366\/039\/3c3\/3660393c319edf2c4ee19d2b1091b2fe.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 connect<\/figcaption><\/div>\n<\/figure>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0432\u043e\u0435\u0434\u0438\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0440\u044b\u0439 API <code>CoreBluetooth<\/code> \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0430\u044f <code>async throws<\/code> \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u2013 <code>actor<\/code><\/p>\n<\/li>\n<li>\n<p><em>\u0421omplete<\/em> \u2013 \u0441\u0430\u043c\u044b\u0439 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 <code>strict mode<\/code><\/p>\n<\/li>\n<\/ul>\n<h2>\u0414\u0435\u043b\u0435\u0433\u0430\u0442\u044b<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 <code>actor<\/code> \u043f\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043e\u0442 <code>CoreBluetooth<\/code>:<\/p>\n<pre><code class=\"swift\">extension BluetoothService: CBCentralManagerDelegate {  func centralManagerDidUpdateState(_ central: CBCentralManager) {}  ... }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<blockquote>\n<p>Actor-isolated instance method &#8216;centralManagerDidUpdateState&#8217; cannot be @objc\u00a0<\/p>\n<p>Actor-isolated instance method &#8216;centralManagerDidUpdateState&#8217; cannot be used to satisfy nonisolated requirement from protocol &#8216;CBCentralManagerDelegate&#8217;\u00a0<\/p>\n<p>Non-&#8216;@objc&#8217; method &#8216;centralManagerDidUpdateState&#8217; does not satisfy requirement of &#8216;@objc&#8217; protocol &#8216;CBCentralManagerDelegate&#8217;<\/p>\n<\/blockquote>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0430\u043a\u0442\u043e\u0440\u0430 \u0438\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>async<\/code>, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u2014 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u0438\u043b\u0438 \u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>nonisolated<\/code>. \u0418\u0442\u0430\u043a, \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043d\u0435\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"swift\">nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager)<\/code><\/pre>\n<blockquote>\n<p>\u0421\u043e <strong>Swift 6.1<\/strong> \u043c\u043e\u0436\u043d\u043e <code>extension'\u044b<\/code> \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043a\u0430\u043a <code>nonisolated<\/code><\/p>\n<\/blockquote>\n<p>\u0418 \u0432\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0443\u0448\u043b\u0438, \u043e\u0434\u043d\u0430\u043a\u043e, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u043d\u0435\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0430\u043a\u0442\u043e\u0440\u0435, \u0434\u0430\u0436\u0435 \u0447\u0435\u0440\u0435\u0437 <code>Task<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c <code>central<\/code>, \u0430 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438:<\/p>\n<pre><code class=\"swift\">nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager) { Task { [weak self] in \/\/ Error await self?.handleBluetoothState(central.state) } }<\/code><\/pre>\n<blockquote>\n<p>Passing closure as a &#8216;sending&#8217; parameter risks causing data races between code in the current task and concurrent execution of the closure<\/p>\n<\/blockquote>\n<p><strong>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/strong><\/p>\n<p>1. \u041e\u0441\u043b\u0430\u0431\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430<\/p>\n<pre><code class=\"swift\">@preconcurrency import CoreBluetooth<\/code><\/pre>\n<p>2. \u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b Sendable \u0432\u0440\u0443\u0447\u043d\u0443\u044e<\/p>\n<pre><code class=\"swift\">extension CBPeripheral: @retroactive @unchecked Sendable {} extension CBCharacteristic: @retroactive @unchecked Sendable {}<\/code><\/pre>\n<p>\u0411\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0414\u0430, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0442\u0430\u043a \u043c\u044b \u043d\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u0443\u044e \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0438\u043d\u0430\u0447\u0435 \u043d\u0435\u043b\u044c\u0437\u044f. \u0412 \u0441\u0432\u043e\u0451 \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 API \u0434\u043b\u044f <code>async\/await<\/code> \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Bluetooth, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a <code>strict mode<\/code>. \u0421\u0430\u043c\u0430\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u2014 <a href=\"https:\/\/github.com\/manolofdez\/AsyncBluetooth\" rel=\"noopener noreferrer nofollow\">AsyncBluetooth<\/a>:\u00a0<\/p>\n<figure class=\"bordered full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98c\/23b\/4a1\/98c23b4a13808a9b23d29a44549b41a8.png\" width=\"966\" height=\"740\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/98c\/23b\/4a1\/98c23b4a13808a9b23d29a44549b41a8.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98c\/23b\/4a1\/98c23b4a13808a9b23d29a44549b41a8.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c connect<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u043e\u0434\u0443\u043b\u044e \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441 \u043d\u0435\u0433\u043e \u0432 \u043d\u0430\u0448 \u0430\u043a\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u044b\u0448\u0435?<\/p>\n<p><strong>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 Combine<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Combine<\/code>. \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043f\u0430\u0431\u043b\u0438\u0448\u0435\u0440 \u0432\u0441\u0451, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 <code>didUpdateValueFor<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0438\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441. \u0412\u044b\u0448\u0435 \u044f \u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 <code>connect()<\/code>, \u0438 \u0447\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434 <code>async\/await<\/code> \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f, \u0442\u0430\u0439\u043c\u0435\u0440 \u0438 \u0442.\u043f.):<\/p>\n<pre><code class=\"swift\">func connect() async throws { startCentralManager()  return try await withUnsafeThrowingContinuation { continuation in publisher .sink { value in  \/\/ \u041e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430  continuation.resume() } .store(in: &amp;subscriptions) } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e, \u0434\u0430? \u0415\u0449\u0451 \u043d\u0430\u0434\u043e \u0443\u0447\u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0442\u044c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c timeout \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u041d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c <\/em><code><em>Combine<\/em><\/code><em> \u0441\u043e <\/em><code><em>Swift Concurrency<\/em><\/code><em>&#8230;<\/em><\/p>\n<\/blockquote>\n<p><strong>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 AsyncStream<\/strong><\/p>\n<p>\u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0448\u0451\u043b <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/asyncstream\" rel=\"noopener noreferrer nofollow\"><code>AsyncStream<\/code><\/a>. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0442\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>yield()<\/code>, \u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>finish()<\/code>. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 <code>for await ... in<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u044d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 <code>async\/await <\/code>\u043f\u0430\u0431\u043b\u0438\u0448\u0435\u0440, \u043a\u0430\u043a \u0438\u0437<code> Combine<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a. <em>\u0418\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u044e\u043c\u0435\u0440\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 <\/em><code><em>Task<\/em><\/code><em>, \u043e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u2014\u00a0\u0431\u0443\u0434\u0435\u0442 \u00ab\u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u00bb.<\/em><\/p>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0433\u0430\u0439\u0434\u0430\u0445 (\u0430 \u0438\u0445 \u043c\u0430\u043b\u043e) \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Apple:\u00a0<\/p>\n<pre><code class=\"swift\">extension QuakeMonitor {      static var quakes: AsyncStream&lt;Quake&gt; {         AsyncStream { continuation in             let monitor = QuakeMonitor()             monitor.quakeHandler = { quake in                 continuation.yield(quake)             }             continuation.onTermination = { @Sendable _ in                  monitor.stopMonitoring()             }             monitor.startMonitoring()         }     } }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>continuation<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u0430\u043b\u043e \u0433\u0434\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0440\u0438\u043c\u0430 \u2014\u00a0\u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u0435 continuation \u043d\u0430\u0440\u0443\u0436\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u0435\u043b\u0430\u0442\u044c <code>yield()<\/code> \u0438 <code>finish()<\/code> \u0432 \u043b\u044e\u0431\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 <a href=\"https:\/\/forums.swift.org\/t\/unlike-other-continuations-in-swift-asyncstream-continuation-supports-escaping\/53254\/5\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435<\/a>. \u041e\u0431 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/asyncstream\/continuation\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/518\/81e\/c07\/51881ec0780423e5fa8abb328e211eb1.png\" width=\"1328\" height=\"242\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/518\/81e\/c07\/51881ec0780423e5fa8abb328e211eb1.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/518\/81e\/c07\/51881ec0780423e5fa8abb328e211eb1.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 <code>BluetoothService<\/code>:<\/p>\n<pre><code class=\"swift\">var continuation: AsyncThrowingStream&lt;String, Error&gt;.Continuation?  var pipe: AsyncThrowingStream&lt;String, Error&gt; { AsyncStream { self.continuation = $0 } }  ...  func connect() async throws { startCentralManager()  for try await message in pipe {  \/\/ \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u043f...        \/\/ \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438:         return } }  ...  nonisolated func peripheral(... didUpdateValueFor characteristic ...) { Task { await continuation.yield(message) } }  nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager) { guard central.state != .poweredOn else { return }  Task { await continuation.finish(throwing: Error) } }<\/code><\/pre>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u0430, <code>continuation<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u043d\u0435\u0441\u0435\u043d \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041c\u0435\u0442\u043e\u0434 <code>connect()<\/code> \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e, \u0436\u0434\u0451\u0442 \u0432 <code>for await loop<\/code> \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0443. \u0418\u0437<code> didUpdateValueFor<\/code> \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0434\u0451\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0440\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <code>.yield()<\/code>.<\/p>\n<p>\u0414\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>AsyncThrowingStream<\/code>. \u0422\u0430\u043a, \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>centralManagerDidUpdateState<\/code>, \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u0440\u0430\u0432\u0435\u043d <code>.unauthorized<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f <code>.finish(throwing:)<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <code>for await loop <\/code>\u0441 \u043a\u0435\u0439\u0432\u043e\u0440\u0434\u043e\u043c <code>try<\/code>.<\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0443\u043f\u0435\u0440! \u041d\u0443\u0436\u0435\u043d async \u2014\u00a0\u0432\u043e\u0442 \u0442\u0435\u0431\u0435 <code>for await loop<\/code>, \u0436\u0434\u0438 \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.\u00a0\u041f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u2014\u00a0\u0432\u044b\u043a\u0438\u043d\u0443\u043b throw \u043f\u0440\u044f\u043c \u0442\u0443\u0442 \u0436\u0435.<\/p>\n<p><strong>\u0422\u0430\u0439\u043c\u0430\u0443\u0442<\/strong>\u00a0<\/p>\n<p>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 BLE-\u043c\u043e\u0434\u0443\u043b\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u00ab\u0437\u0430\u0432\u0438\u0441\u043d\u0443\u0442\u044c\u00bb \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0430\u043b\u0435\u043a\u043e \u0438\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e. \u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u2014 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 <em>N-\u043e\u0433\u043e<\/em> \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0442\u043e \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <code>connect()<\/code> \u043e\u0448\u0438\u0431\u043a\u0443.\u00a0<\/p>\n<p>\u0412 Concurrency \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u043e\u0434\u0438\u043d await \u0432 \u0441\u043a\u043e\u0443\u043f\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0434\u0432\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>withTaskGroup<\/code>, \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u0433\u0440\u0443\u043f\u043f\u0443 \u0437\u0430\u0434\u0430\u0447 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a AsyncSequence (\u043e\u0442 \u043d\u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0438 AsyncStream), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0442\u0430\u0441\u043e\u043a:<\/p>\n<pre><code class=\"swift\">try await withThrowingTaskGroup { group in  group.addTask { for try await message in pipe { \/\/ \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f... } }  group.addTask { try await Task.sleep(for: N) throw BluetoothError.timeout }  guard let result = try await group.next() else { throw BluetoothError } group.cancelAll() return result }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u042f \u043f\u0435\u0440\u0435\u043d\u0451\u0441 <code>for await loop<\/code> \u0432 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0442\u0430\u0441\u043e\u043a \u044d\u0442\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b. \u0412 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0441\u043a\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u0441\u043f\u0438\u043c\u00bb <em>N \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/em> \u0438 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441 <code>group<\/code> (\u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u0442\u0430\u0441\u043a\u0438) \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>.next()<\/code>. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0438\u0431\u043e \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0441\u043a\u043e\u0443\u043f\u0430, \u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0430 <code>timeout<\/code>.<\/p>\n<blockquote>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044f \u043e\u0431\u0435\u0440\u043d\u0443\u043b \u044d\u0442\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>withTimeout<\/code>, \u043a\u0443\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c async throws \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0436\u0434\u0430\u0442\u044c \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c.<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0445\u043e\u0436\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430.<\/p>\n<h2>\u0418\u0442\u043e\u0433\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 <code>strict mode<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u0451\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0441\u0447\u0451\u0442 actor \u0431\u0435\u0437 \u0440\u0443\u0447\u043d\u044b\u0445 \u043b\u043e\u043a\u043e\u0432 \u0438 <code>DispatchQueue<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 <code>AsyncStream<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044f\u0441\u044c \u043e\u0442 \u0433\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u043d\u0430 <code>async\/await<\/code>, \u0431\u0435\u0437 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u043e\u0432 \u0438 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u00ab\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u00bb \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043d\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430\u0445 \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u0445, \u043a\u043e\u0434 \u0441\u0442\u0430\u043b \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435, \u0447\u0438\u0442\u0430\u0435\u043c\u0435\u0435 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u0435\u0435. \u0414\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442: \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0444\u043e\u043a\u0443\u0441\u0430 \u043d\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443. \u0415\u0441\u043b\u0438 \u0437\u0430\u0432\u0442\u0440\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 BLE-\u043c\u043e\u0434\u0443\u043b\u044c \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u2014 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435.<\/p>\n<p>\u0418 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435: \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 <code>Swift Concurrency<\/code>, \u0431\u0435\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u0431\u0435\u0437 \u043e\u0431\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u0430\u043d\u0451\u0432\u0440\u043e\u0432 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/946328\/\"> https:\/\/habr.com\/ru\/articles\/946328\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435: \u0432\u044b \u043f\u0440\u0438\u043b\u0435\u0442\u0430\u0435\u0442\u0435 \u0432 \u0430\u044d\u0440\u043e\u043f\u043e\u0440\u0442, \u0431\u0440\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c \u043a\u0430\u0440\u0448\u0435\u0440\u0438\u043d\u0433\u0430, \u043d\u043e \u0430\u0432\u0442\u043e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u0440\u043a\u043e\u0432\u043a\u0435. \u0423 \u0432\u0430\u0448\u0435\u0433\u043e iPhone \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0435\u0441\u0442\u044c, \u043d\u043e \u0443 \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0432\u044f\u0437\u0438 \u043d\u0435\u0442 \u2014 \u043e\u043d\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043a\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0430\u0432\u0442\u043e?<\/p>\n<p>\u041d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0441\u0435\u0442\u044c\u044e \u0432 \u0421\u0438\u0442\u0438\u0434\u0440\u0430\u0439\u0432\u0435 \u0435\u0441\u0442\u044c \u043e\u0444\u0444\u043b\u0430\u0439\u043d-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0432\u0435\u0440\u044c\u043c\u0438 \u043c\u0430\u0448\u0438\u043d\u044b \u0447\u0435\u0440\u0435\u0437 Bluetooth. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0431\u043b\u043e\u043a\u0435 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u0441 \u043d\u0438\u043c iPhone \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u0432\u0435\u0440\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u00ab\u043e\u0442\u0440\u0435\u0437\u0430\u043d\u0430\u00bb \u043e\u0442 \u0441\u0435\u0442\u0438. \u0422\u0430\u043a, Bluetooth \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0432\u0442\u043e \u0432 \u043b\u044e\u0431\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.<\/p>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0438. \u042f \u0432\u0437\u044f\u043b \u043d\u0430 \u0441\u0435\u0431\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u043e iOS \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 <code>Swift Concurrency<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 \u0441\u0442\u0430\u0440\u043e\u0433\u043e <code>CoreBluetooth<\/code>. \u041a\u0430\u043a \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a 20 000 \u043c\u0430\u0448\u0438\u043d \u0447\u0435\u0440\u0435\u0437 Bluetooth <a href=\"https:\/\/habr.com\/ru\/companies\/citydrive\/articles\/943792\/\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u043e\u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u0432\u044b\u043b\u0435\u0437\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0438 structured concurrency \u0438 callback-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e API, \u043a\u0430\u043a \u0438\u0445 \u043e\u0431\u043e\u0439\u0442\u0438 \u0438 \u043d\u0430 \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0442\u043e\u0436\u0435 \u0440\u0435\u0448\u0438\u0442\u0435 \u00ab\u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c\u00bb \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 async\/await \u043a \u0441\u0442\u0430\u0440\u043e\u043c\u0443 API.<\/p>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0430\u0432\u0442\u043e?<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Bluetooth-\u043c\u043e\u0434\u0443\u043b\u044e \u0441 iPhone \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \u041c\u043e\u0434\u0443\u043b\u044c \u0440\u0430\u0437 \u0432 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435. \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <em>\u0442\u0440\u0443\u0431\u0443<\/em>, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u2014 \u043e\u043d \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0434\u043d\u0435\u0435. \u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043c\u043e\u0434\u0443\u043b\u044c, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u0440\u0438\u0434\u0451\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: \u0443\u0441\u043f\u0435\u0445, \u0441\u0442\u0430\u0442\u0443\u0441 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u043e\u0434\u0443\u043b\u044c \u2014 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0442\u0440\u0443\u0431\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u044b\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u044b.<\/p>\n<h2>CoreBluetooth <\/h2>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 BLE \u0432 iOS \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <a href=\"https:\/\/developer.apple.com\/documentation\/corebluetooth\" rel=\"noopener noreferrer nofollow\">\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <code>CoreBluetooth<\/code><\/a>. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u0430 \u0434\u0435\u043b\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430. \u0421 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044f: \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0442\u0430\u0442\u0443\u0441\u044b \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p><strong>\u0412\u043e\u0442 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/strong><\/p>\n<p><em>CBCentralManagerDelegate<\/em><\/p>\n<pre><code class=\"swift\">\/\/ \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 Bluetooth \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 func centralManagerDidUpdateState(_ central: CBCentralManager)  \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e BLE-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func centralManager(... didDiscover peripheral ...)  \/\/ \u0421\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443 func centralManager(... didConnect peripheral ...)<\/code><\/pre>\n<p><em>CBPeripheralDelegate<\/em><\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func peripheral(... didUpdateValueFor characteristic ...)  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 func peripheral(... didDiscoverServices error ...)  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 func peripheral(... didDiscoverCharacteristicsFor service ...) <\/code><\/pre>\n<p>\u0410 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>CBCentralManager<\/code>. \u0412\u0441\u0451 \u044d\u0442\u043e \u044f \u0432\u044b\u043d\u0435\u0441 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 BLE \u0438 \u043d\u0435 \u0440\u0430\u0437\u043c\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043f\u043e \u043a\u043e\u0434\u0443. \u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430: \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0438\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 <code>didUpdateValueFor<\/code>.<\/p>\n<h2>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443<\/h2>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0430 <strong>Swift 6<\/strong>, \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430 \u2014 <code>Swift Concurrency<\/code> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 <code>strict mode<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 Bluetooth \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u044f\u0437\u044b\u043a\u0430, \u043d\u043e \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a callback\u2019\u0430\u043c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d <code>actor.<\/code> \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"swift\">protocol BluetoothServiceProtocol {  func connect() async throws  func disconnect() async  func write(_ message: String) async throws }  actor BluetoothService: BluetoothServiceProtocol<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <code>connect()<\/code> \u2014 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/strong> \u0432 \u043c\u043e\u0434\u0443\u043b\u0435. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0438 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043c\u043e\u0434\u0443\u043b\u044c, \u0434\u0430\u043b\u0435\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c. <strong>\u0422\u043e\u043b\u044c\u043a\u043e<\/strong> \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 <code>connect()<\/code>. \u0415\u0449\u0451 \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u2014 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c <code>timeout<\/code>.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 connect<\/figcaption><\/div>\n<\/figure>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0432\u043e\u0435\u0434\u0438\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c-\u0442\u0440\u0443\u0431\u0430, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0440\u044b\u0439 API <code>CoreBluetooth<\/code> \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0430\u044f <code>async throws<\/code> \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u2013 <code>actor<\/code><\/p>\n<\/li>\n<li>\n<p><em>\u0421omplete<\/em> \u2013 \u0441\u0430\u043c\u044b\u0439 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 <code>strict mode<\/code><\/p>\n<\/li>\n<\/ul>\n<h2>\u0414\u0435\u043b\u0435\u0433\u0430\u0442\u044b<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 <code>actor<\/code> \u043f\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u043e\u0442 <code>CoreBluetooth<\/code>:<\/p>\n<pre><code class=\"swift\">extension BluetoothService: CBCentralManagerDelegate {  func centralManagerDidUpdateState(_ central: CBCentralManager) {}  ... }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<blockquote>\n<p>Actor-isolated instance method &#8216;centralManagerDidUpdateState&#8217; cannot be @objc\u00a0<\/p>\n<p>Actor-isolated instance method &#8216;centralManagerDidUpdateState&#8217; cannot be used to satisfy nonisolated requirement from protocol &#8216;CBCentralManagerDelegate&#8217;\u00a0<\/p>\n<p>Non-&#8216;@objc&#8217; method &#8216;centralManagerDidUpdateState&#8217; does not satisfy requirement of &#8216;@objc&#8217; protocol &#8216;CBCentralManagerDelegate&#8217;<\/p>\n<\/blockquote>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0430\u043a\u0442\u043e\u0440\u0430 \u0438\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>async<\/code>, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u2014 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u0438\u043b\u0438 \u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>nonisolated<\/code>. \u0418\u0442\u0430\u043a, \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043d\u0435\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"swift\">nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager)<\/code><\/pre>\n<blockquote>\n<p>\u0421\u043e <strong>Swift 6.1<\/strong> \u043c\u043e\u0436\u043d\u043e <code>extension'\u044b<\/code> \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043a\u0430\u043a <code>nonisolated<\/code><\/p>\n<\/blockquote>\n<p>\u0418 \u0432\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0443\u0448\u043b\u0438, \u043e\u0434\u043d\u0430\u043a\u043e, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u043d\u0435\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0430\u043a\u0442\u043e\u0440\u0435, \u0434\u0430\u0436\u0435 \u0447\u0435\u0440\u0435\u0437 <code>Task<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c <code>central<\/code>, \u0430 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438:<\/p>\n<pre><code class=\"swift\">nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager) { Task { [weak self] in \/\/ Error await self?.handleBluetoothState(central.state) } }<\/code><\/pre>\n<blockquote>\n<p>Passing closure as a &#8216;sending&#8217; parameter risks causing data races between code in the current task and concurrent execution of the closure<\/p>\n<\/blockquote>\n<p><strong>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/strong><\/p>\n<p>1. \u041e\u0441\u043b\u0430\u0431\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430<\/p>\n<pre><code class=\"swift\">@preconcurrency import CoreBluetooth<\/code><\/pre>\n<p>2. \u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b Sendable \u0432\u0440\u0443\u0447\u043d\u0443\u044e<\/p>\n<pre><code class=\"swift\">extension CBPeripheral: @retroactive @unchecked Sendable {} extension CBCharacteristic: @retroactive @unchecked Sendable {}<\/code><\/pre>\n<p>\u0411\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0414\u0430, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0442\u0430\u043a \u043c\u044b \u043d\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u0443\u044e \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0438\u043d\u0430\u0447\u0435 \u043d\u0435\u043b\u044c\u0437\u044f. \u0412 \u0441\u0432\u043e\u0451 \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 API \u0434\u043b\u044f <code>async\/await<\/code> \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Bluetooth, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a <code>strict mode<\/code>. \u0421\u0430\u043c\u0430\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u2014 <a href=\"https:\/\/github.com\/manolofdez\/AsyncBluetooth\" rel=\"noopener noreferrer nofollow\">AsyncBluetooth<\/a>:\u00a0<\/p>\n<figure class=\"bordered full-width\"><\/figure>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c connect<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u043e\u0434\u0443\u043b\u044e \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441 \u043d\u0435\u0433\u043e \u0432 \u043d\u0430\u0448 \u0430\u043a\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u044b\u0448\u0435?<\/p>\n<p><strong>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 Combine<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Combine<\/code>. \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043f\u0430\u0431\u043b\u0438\u0448\u0435\u0440 \u0432\u0441\u0451, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 <code>didUpdateValueFor<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0438\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441. \u0412\u044b\u0448\u0435 \u044f \u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 <code>connect()<\/code>, \u0438 \u0447\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434 <code>async\/await<\/code> \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f, \u0442\u0430\u0439\u043c\u0435\u0440 \u0438 \u0442.\u043f.):<\/p>\n<pre><code class=\"swift\">func connect() async throws { startCentralManager()  return try await withUnsafeThrowingContinuation { continuation in publisher .sink { value in  \/\/ \u041e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430  continuation.resume() } .store(in: &amp;subscriptions) } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e, \u0434\u0430? \u0415\u0449\u0451 \u043d\u0430\u0434\u043e \u0443\u0447\u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0442\u044c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c timeout \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u041d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c <\/em><code><em>Combine<\/em><\/code><em> \u0441\u043e <\/em><code><em>Swift Concurrency<\/em><\/code><em>&#8230;<\/em><\/p>\n<\/blockquote>\n<p><strong>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 AsyncStream<\/strong><\/p>\n<p>\u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0448\u0451\u043b <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/asyncstream\" rel=\"noopener noreferrer nofollow\"><code>AsyncStream<\/code><\/a>. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0442\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>yield()<\/code>, \u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>finish()<\/code>. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 <code>for await ... in<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u044d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 <code>async\/await <\/code>\u043f\u0430\u0431\u043b\u0438\u0448\u0435\u0440, \u043a\u0430\u043a \u0438\u0437<code> Combine<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a. <em>\u0418\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u044e\u043c\u0435\u0440\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 <\/em><code><em>Task<\/em><\/code><em>, \u043e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u2014\u00a0\u0431\u0443\u0434\u0435\u0442 \u00ab\u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u00bb.<\/em><\/p>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0433\u0430\u0439\u0434\u0430\u0445 (\u0430 \u0438\u0445 \u043c\u0430\u043b\u043e) \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Apple:\u00a0<\/p>\n<pre><code class=\"swift\">extension QuakeMonitor {      static var quakes: AsyncStream&lt;Quake&gt; {         AsyncStream { continuation in             let monitor = QuakeMonitor()             monitor.quakeHandler = { quake in                 continuation.yield(quake)             }             continuation.onTermination = { @Sendable _ in                  monitor.stopMonitoring()             }             monitor.startMonitoring()         }     } }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>continuation<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u0430\u043b\u043e \u0433\u0434\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0440\u0438\u043c\u0430 \u2014\u00a0\u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u0435 continuation \u043d\u0430\u0440\u0443\u0436\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u0435\u043b\u0430\u0442\u044c <code>yield()<\/code> \u0438 <code>finish()<\/code> \u0432 \u043b\u044e\u0431\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 <a href=\"https:\/\/forums.swift.org\/t\/unlike-other-continuations-in-swift-asyncstream-continuation-supports-escaping\/53254\/5\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435<\/a>. \u041e\u0431 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/asyncstream\/continuation\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 <code>BluetoothService<\/code>:<\/p>\n<pre><code class=\"swift\">var continuation: AsyncThrowingStream&lt;String, Error&gt;.Continuation?  var pipe: AsyncThrowingStream&lt;String, Error&gt; { AsyncStream { self.continuation = $0 } }  ...  func connect() async throws { startCentralManager()  for try await message in pipe {  \/\/ \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u043f...        \/\/ \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438:         return } }  ...  nonisolated func peripheral(... didUpdateValueFor characteristic ...) { Task { await continuation.yield(message) } }  nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager) { guard central.state != .poweredOn else { return }  Task { await continuation.finish(throwing: Error) } }<\/code><\/pre>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u0430, <code>continuation<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u043d\u0435\u0441\u0435\u043d <\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-474768","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474768","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474768"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474768\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}