{"id":395963,"date":"2024-06-29T12:32:59","date_gmt":"2024-06-29T12:32:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=395963"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T12:32:59","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=395963","title":{"rendered":"<span>Kotlin Native. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043f\u0430\u043c\u044f\u0442\u0438<\/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 loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e5e\/e45\/2b1\/e5ee452b13ca495405e3e1487ef4e88c.png\" width=\"640\" height=\"348\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e5e\/e45\/2b1\/e5ee452b13ca495405e3e1487ef4e88c.png\"\/><figcaption><\/figcaption><\/figure>\n<p><em>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0434\u043d\u044f! \u0421 \u0432\u0430\u043c\u0438 \u0410\u043d\u043d\u0430 \u0416\u0430\u0440\u043a\u043e\u0432\u0430, \u0432\u0435\u0434\u0443\u0449\u0438\u0439 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Usetech. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 Kotlin Native. <br \/>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e <\/em><a href=\"https:\/\/habr.com\/ru\/post\/577464\/\" rel=\"noopener noreferrer nofollow\"><em>\u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/em><\/a><em> \u0438 <\/em><a href=\"https:\/\/habr.com\/ru\/post\/577488\/\" rel=\"noopener noreferrer nofollow\"><em>\u0431\u0435\u0437<\/em><\/a><em>, \u0438 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0431\u043e\u043b\u044f\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u043e.<\/em><\/p>\n<p>31 \u0430\u0432\u0433\u0443\u0441\u0442\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f JetBrains \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u044c\u044e <a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/08\/try-the-new-kotlin-native-memory-manager-development-preview\/\" rel=\"noopener noreferrer nofollow\">\u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 Kotlin Native<\/a>.  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0443\u043f\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u043b\u0430 \u043d\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0448\u0430\u0440\u0438\u043d\u0433\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0441 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u0441\u043d\u0443\u043b\u0430\u0441\u044c Coroutines, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u043e\u043f\u0430\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0431\u0435\u0437 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u043b\u0438 \u0438 Ktor:  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u0436\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 Kotlin 1.6.0-M1-139: <br \/>1. \u0417\u0430\u044f\u0432\u043b\u0435\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 <em>freeze<\/em>() \u0431\u043b\u043e\u043a\u0438 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 <em>Worker<\/em>), \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. <\/p>\n<p>2.\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <em>AtomicReference<\/em> \u0438\u043b\u0438 <em>FreezableAtomicReference<\/em> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>3.\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>SharedImmutable<\/em>.<\/p>\n<p>4.\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Worker.execute producer \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0433\u0440\u0430\u0444 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u0438 \u043d\u044e\u0430\u043d\u0441\u044b:<br \/>1. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 AtomicReference. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong><em>FreezableAtomicReference<\/em><\/strong> \u0438\u043b\u0438 <strong><em>AtomicRef<\/em><\/strong> \u0438\u0437 <strong><em>atomicfu<\/em> <\/strong>. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u0441 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e atomicfu \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 1.\u0445. <\/p>\n<p>2.\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 suspend \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Kotlin \u0432 Swift  \u0435\u0435 completion handler \u0431\u043b\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0439\u0442\u0438 \u0432 main thread. \u0422.\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c DispatchQueue.main.async{&#8230;}, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. <\/p>\n<p>3.deInit Swift\/ObjC \u043e\u0431\u044a\u043a\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. <\/p>\n<p>4.\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u0442.\u0435 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438. \u0420\u0430\u043d\u0435\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <strong><em>@&#8217;EagerInitialization<\/em><\/strong>. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u0435\u0440\u0435\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041d\u044e\u0430\u043d\u0441\u044b \u0435\u0441\u0442\u044c \u0438 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438,  \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0439 \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e:<\/p>\n<p>1.\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 <em>Worker<\/em> \u0441 <em>Channel<\/em> \u0438 <em>Flow<\/em> \u0431\u0435\u0437 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438.  \u0418 \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 native-mt \u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043d\u0430\u043b\u0430 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u0438\u0442\u044c \u0432\u0441\u0435 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>2.<em>Dispatchers.Default<\/em> \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f global queue.<\/p>\n<p>3.<em>newSingleThreadContext<\/em> \u0438 <em>newFixedThreadPoolContext<\/em> \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043f\u0443\u043b\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.<\/p>\n<p>4.<em>Dispatchers.Main<\/em> \u0441\u0432\u044f\u0437\u0430\u043d \u0441 main queue \u0434\u043b\u044f Darwin \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c Worker \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c Native. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Unit \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p>\u041d\u044e\u0430\u043d\u0441\u043e\u0432 \u043c\u043d\u043e\u0433\u043e, \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0435\u0440\u0444\u043e\u0440\u043c\u0430\u043d\u0441\u043e\u043c \u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0431\u0430\u0433\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/a> \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0432\u044c\u044e (\u0434\u0430\u0436\u0435 \u043d\u0435 \u0430\u043b\u044c\u0444\u0430).<\/p>\n<p>\u0427\u0442\u043e \u0436, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e\u0434 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438. <br \/>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0435\u0440\u0441\u0438\u0438 1.6.0-M1-139 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"kotlin\">\/\/ build.gradle.kts buildscript {     repositories {         gradlePluginPortal()         google()         mavenCentral()         maven(\"https:\/\/maven.pkg.jetbrains.space\/kotlin\/p\/kotlin\/temporary\")     }     dependencies {         classpath(\"org.jetbrains.kotlin:kotlin-gradle-plugin:${findProperty(\"version.kotlin\")}\")         classpath(\"org.jetbrains.kotlin:kotlin-serialization:${findProperty(\"version.kotlin\")}\")         classpath(\"com.android.tools.build:gradle:${findProperty(\"version.androidGradlePlugin\")}\")     } }  \/\/ settings.gradle.kts  pluginManagement {     repositories {         gradlePluginPortal()         google()         mavenCentral()         maven {             url = uri(\"https:\/\/maven.pkg.jetbrains.space\/kotlin\/p\/kotlin\/dev\")         }         maven {             url = uri(\"https:\/\/maven.pkg.jetbrains.space\/public\/p\/kotlinx-coroutines\/maven\")         }         }     } }<\/code><\/pre>\n<pre><code class=\"kotlin\">\/\/gradle.properties kotlin.native.binary.memoryModel=experimental  #kotlin.native.binary.freezing=disabled  #Common versions version.kotlin=1.6.0-M1-139 version.androidGradlePlugin=7.0.0 version.kotlinx.serialization=1.2.2 version.kotlinx.coroutines=1.5.1-new-mm-dev2<\/code><\/pre>\n<p>\u0418 \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d:<\/p>\n<pre><code class=\"kotlin\">\/\/version.kotlinx.coroutines=1.5.1-new-mm-dev2  val commonMain by getting {             dependencies {                 implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:${findProperty(\"version.kotlinx.coroutines\")}\")             }         }           <\/code><\/pre>\n<p><em>\u0412\u0430\u0436\u043d\u043e! \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Xcode \u0432\u0435\u0440\u0441\u0438\u0438 12.5 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435. \u042d\u0442\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 1.6.0-M1-139. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0443\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0441\u0438\u0439 Xcode, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u0435, \u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e xcode-select, \u0437\u0430\u043a\u0440\u043e\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 Kotlin Multiplatform \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 Invalidate cache and Restart. \u0418\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0435\u0440\u0441\u0438\u0438.<\/em> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0431\u043e\u0440\u043a\u0438 freeze() \u0431\u043b\u043e\u043a\u043e\u0432 \u0438\u0437 \u0431\u0435\u0441\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<pre><code class=\"kotlin\">\/\/Worker internal fun background(block: () -> Unit) {     val future = worker.execute(TransferMode.SAFE, { block}) {         it()     }     collectFutures.add(future) }  \/\/Main wrapper internal fun main(block:()->Unit) {     dispatch_async(dispatch_get_main_queue()) {             block()      } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0440\u0435\u043c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f UrlSession (\u0443 \u043d\u0430\u0441 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442):<\/p>\n<pre><code class=\"kotlin\">fun request(request: Request, completion: (Response) -> Unit) {         this.completion = completion         val responseReader = ResponseReader().apply { this.responseListener = this@HttpEngine }         val urlSession =             NSURLSession.sessionWithConfiguration(                 NSURLSessionConfiguration.defaultSessionConfiguration, responseReader,                 delegateQueue = NSOperationQueue.currentQueue()             )          val urlRequest =             NSMutableURLRequest(NSURL.URLWithString(request.url)!!).apply {                 setAllHTTPHeaderFields(request.headers)                 setHTTPMethod(request.method.value)                 setCachePolicy(NSURLRequestReloadIgnoringCacheData)              }          fun doRequest() {             val task = urlSession.dataTaskWithRequest(urlRequest)             task?.resume()         }          background{             doRequest()         }     }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043e\u043a \u043c\u0435\u043d\u044f\u0435\u043c AtomicReference \u043d\u0430 FreezableAtomicReference:<\/p>\n<pre><code class=\"kotlin\">\/* internal fun &lt;T> T.atomic(): AtomicReference&lt;T>{     return AtomicReference(this.share()) }*\/  internal fun &lt;T> T.atomic(): FreezableAtomicReference&lt;T>{     return FreezableAtomicReference(this) }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434, \u0433\u0434\u0435 \u043c\u044b \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\"> private fun updateChunks(data: NSData) {         var newValue = ByteArray(0)         newValue += chunks.value         newValue += data.toByteArray()         chunks.value = newValue\/\/.share()     }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0442\u0430\u043a \u0438 \u0434\u044b\u0448\u0438\u0442 \u0447\u0438\u0441\u0442\u043e\u0442\u043e\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043b\u0435\u0442\u0430\u0435\u0442, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e GC (\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">\u0431\u043e\u043b\u0438<\/a>) \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0442\u044e\u043d\u0438\u043d\u0433\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438:<\/p>\n<pre><code class=\"kotlin\">val uiDispatcher: CoroutineContext = Dispatchers.Main val ioDispatcher: CoroutineContext = Dispatchers.Default<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u0430\u0433\u0438\u044e GlobalQueue, \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c ioDispatcher:<\/p>\n<pre><code class=\"swift\"> \/\/output StandaloneCoroutine{Active}@26dbcd0, DarwinGlobalQueueDispatcher@28ea470<\/code><\/pre>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Flow \u0438\/\u0438\u043b\u0438 Channel:<\/p>\n<pre><code class=\"kotlin\">class FlowResponseReader : NSObject(),     NSURLSessionDataDelegateProtocol {     private var chunksFlow = MutableStateFlow(ByteArray(0))     private var rawResponse = CompletableDeferred&lt;Response>()      suspend fun awaitResponse(): Response {         var chunks = ByteArray(0)          chunksFlow.onEach {             chunks += it         }.launchIn(scope)         val response = rawResponse.await()         response.content = chunks.string()         return response     }     \/***\/      private fun updateChunks(data: NSData) {         val bytes = data.toByteArray()         chunksFlow.tryEmit(bytes)     } }<\/code><\/pre>\n<p> \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e.  \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c main thread:<\/p>\n<pre><code class=\"kotlin\">actual override suspend fun request(request: Request):Response {          val response = engine.request(request)         return withContext(uiDispatcher){response}     }<\/code><\/pre>\n<p><em>\u0412\u0430\u0436\u043d\u043e! \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0443\u0442\u0435\u0447\u0435\u043a \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435  iOS, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Swift\/ObjC, \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0436\u0435\u043d\u0438\u044f GC \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0431\u043b\u043e\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0432  autoreleasepool.<\/em> <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430 MainScope, \u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e newSingleThreadContext \u0443\u043a\u0430\u0436\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\"> val task = urlSession.dataTaskWithRequest(urlRequest)         mainScope.launch(newSingleThreadContext(\"MyOwnThread\")) {           print(\"${this.coroutineContext}\")             task?.resume()         } \/\/output  [StandaloneCoroutine{Active}@384d2a0, WorkerDispatcher@384d630]<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u0435\u0437 \u0437\u0430\u043f\u0438\u043d\u043e\u043a. \u0421 \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043b\u0435\u0447 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u043a\u043e\u0440\u043e \u0441\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0433\u043e\u0440\u0430 \u0437\u0430\u0431\u043e\u0442. <br \/>\u041d\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0436\u0438\u0440\u043d\u043e\u0435 &#171;\u041d\u041e&#187;. \u041d\u0435 \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 KMM, \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e\u0432\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443 \u043a \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 InvalidMutabilityException \u0438\u043b\u0438 FreezingException.<br \/>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0441 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 1.6.0-M1-139 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443:<\/p>\n<pre><code class=\"kotlin\">\/\/gradle.properties kotlin.native.binary.freezing=disabled  \/\/\u043b\u0438\u0431\u043e build.gradle.kts kotlin.targets.withType(KotlinNativeTarget::class.java) {     binaries.all {         binaryOptions[\"freezing\"] = \"disabled\"     } } <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md<\/a><\/p>\n<p>\u0418 \u0441\u044d\u043c\u043f\u043b \u043d\u0430 \u043a\u043e\u043b\u0435\u043d\u043a\u0435: <br \/><a href=\"https:\/\/github.com\/anioutkazharkova\/kotlin_native_network_client\/tree\/feature\/1.6-kn\/sample\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/anioutkazharkova\/kotlin_native_network_client\/tree\/feature\/1.6-kn\/sample<\/a><\/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\/578716\/\"> https:\/\/habr.com\/ru\/articles\/578716\/<\/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\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0434\u043d\u044f! \u0421 \u0432\u0430\u043c\u0438 \u0410\u043d\u043d\u0430 \u0416\u0430\u0440\u043a\u043e\u0432\u0430, \u0432\u0435\u0434\u0443\u0449\u0438\u0439 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Usetech. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 Kotlin Native. <br \/>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e <\/em><a href=\"https:\/\/habr.com\/ru\/post\/577464\/\" rel=\"noopener noreferrer nofollow\"><em>\u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/em><\/a><em> \u0438 <\/em><a href=\"https:\/\/habr.com\/ru\/post\/577488\/\" rel=\"noopener noreferrer nofollow\"><em>\u0431\u0435\u0437<\/em><\/a><em>, \u0438 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0431\u043e\u043b\u044f\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u043e.<\/em><\/p>\n<p>31 \u0430\u0432\u0433\u0443\u0441\u0442\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f JetBrains \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u044c\u044e <a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2021\/08\/try-the-new-kotlin-native-memory-manager-development-preview\/\" rel=\"noopener noreferrer nofollow\">\u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 Kotlin Native<\/a>.  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0443\u043f\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u043b\u0430 \u043d\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0448\u0430\u0440\u0438\u043d\u0433\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0441 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u0441\u043d\u0443\u043b\u0430\u0441\u044c Coroutines, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u043e\u043f\u0430\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0431\u0435\u0437 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u043b\u0438 \u0438 Ktor:  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u0436\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 Kotlin 1.6.0-M1-139: <br \/>1. \u0417\u0430\u044f\u0432\u043b\u0435\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 <em>freeze<\/em>() \u0431\u043b\u043e\u043a\u0438 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 <em>Worker<\/em>), \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. <\/p>\n<p>2.\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <em>AtomicReference<\/em> \u0438\u043b\u0438 <em>FreezableAtomicReference<\/em> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>3.\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>SharedImmutable<\/em>.<\/p>\n<p>4.\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Worker.execute producer \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0433\u0440\u0430\u0444 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u0438 \u043d\u044e\u0430\u043d\u0441\u044b:<br \/>1. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 AtomicReference. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong><em>FreezableAtomicReference<\/em><\/strong> \u0438\u043b\u0438 <strong><em>AtomicRef<\/em><\/strong> \u0438\u0437 <strong><em>atomicfu<\/em> <\/strong>. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u0441 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e atomicfu \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 1.\u0445. <\/p>\n<p>2.\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 suspend \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Kotlin \u0432 Swift  \u0435\u0435 completion handler \u0431\u043b\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0439\u0442\u0438 \u0432 main thread. \u0422.\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c DispatchQueue.main.async{&#8230;}, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. <\/p>\n<p>3.deInit Swift\/ObjC \u043e\u0431\u044a\u043a\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. <\/p>\n<p>4.\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u0442.\u0435 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438. \u0420\u0430\u043d\u0435\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <strong><em>@&#8217;EagerInitialization<\/em><\/strong>. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u0435\u0440\u0435\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041d\u044e\u0430\u043d\u0441\u044b \u0435\u0441\u0442\u044c \u0438 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438,  \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0439 \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e:<\/p>\n<p>1.\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 <em>Worker<\/em> \u0441 <em>Channel<\/em> \u0438 <em>Flow<\/em> \u0431\u0435\u0437 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438.  \u0418 \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 native-mt \u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043d\u0430\u043b\u0430 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u0438\u0442\u044c \u0432\u0441\u0435 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>2.<em>Dispatchers.Default<\/em> \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f global queue.<\/p>\n<p>3.<em>newSingleThreadContext<\/em> \u0438 <em>newFixedThreadPoolContext<\/em> \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043f\u0443\u043b\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.<\/p>\n<p>4.<em>Dispatchers.Main<\/em> \u0441\u0432\u044f\u0437\u0430\u043d \u0441 main queue \u0434\u043b\u044f Darwin \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c Worker \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c Native. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Unit \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p>\u041d\u044e\u0430\u043d\u0441\u043e\u0432 \u043c\u043d\u043e\u0433\u043e, \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0435\u0440\u0444\u043e\u0440\u043c\u0430\u043d\u0441\u043e\u043c \u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0431\u0430\u0433\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/a> \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0432\u044c\u044e (\u0434\u0430\u0436\u0435 \u043d\u0435 \u0430\u043b\u044c\u0444\u0430).<\/p>\n<p>\u0427\u0442\u043e \u0436, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e\u0434 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438. <br \/>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0435\u0440\u0441\u0438\u0438 1.6.0-M1-139 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"kotlin\">\/\/ build.gradle.kts buildscript {     repositories {         gradlePluginPortal()         google()         mavenCentral()         maven(\"https:\/\/maven.pkg.jetbrains.space\/kotlin\/p\/kotlin\/temporary\")     }     dependencies {         classpath(\"org.jetbrains.kotlin:kotlin-gradle-plugin:${findProperty(\"version.kotlin\")}\")         classpath(\"org.jetbrains.kotlin:kotlin-serialization:${findProperty(\"version.kotlin\")}\")         classpath(\"com.android.tools.build:gradle:${findProperty(\"version.androidGradlePlugin\")}\")     } }  \/\/ settings.gradle.kts  pluginManagement {     repositories {         gradlePluginPortal()         google()         mavenCentral()         maven {             url = uri(\"https:\/\/maven.pkg.jetbrains.space\/kotlin\/p\/kotlin\/dev\")         }         maven {             url = uri(\"https:\/\/maven.pkg.jetbrains.space\/public\/p\/kotlinx-coroutines\/maven\")         }         }     } }<\/code><\/pre>\n<pre><code class=\"kotlin\">\/\/gradle.properties kotlin.native.binary.memoryModel=experimental  #kotlin.native.binary.freezing=disabled  #Common versions version.kotlin=1.6.0-M1-139 version.androidGradlePlugin=7.0.0 version.kotlinx.serialization=1.2.2 version.kotlinx.coroutines=1.5.1-new-mm-dev2<\/code><\/pre>\n<p>\u0418 \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d:<\/p>\n<pre><code class=\"kotlin\">\/\/version.kotlinx.coroutines=1.5.1-new-mm-dev2  val commonMain by getting {             dependencies {                 implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:${findProperty(\"version.kotlinx.coroutines\")}\")             }         }           <\/code><\/pre>\n<p><em>\u0412\u0430\u0436\u043d\u043e! \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Xcode \u0432\u0435\u0440\u0441\u0438\u0438 12.5 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435. \u042d\u0442\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 1.6.0-M1-139. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0443\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0441\u0438\u0439 Xcode, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u0435, \u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e xcode-select, \u0437\u0430\u043a\u0440\u043e\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 Kotlin Multiplatform \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 Invalidate cache and Restart. \u0418\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0435\u0440\u0441\u0438\u0438.<\/em> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0431\u043e\u0440\u043a\u0438 freeze() \u0431\u043b\u043e\u043a\u043e\u0432 \u0438\u0437 \u0431\u0435\u0441\u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<pre><code class=\"kotlin\">\/\/Worker internal fun background(block: () -> Unit) {     val future = worker.execute(TransferMode.SAFE, { block}) {         it()     }     collectFutures.add(future) }  \/\/Main wrapper internal fun main(block:()->Unit) {     dispatch_async(dispatch_get_main_queue()) {             block()      } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0440\u0435\u043c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f UrlSession (\u0443 \u043d\u0430\u0441 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442):<\/p>\n<pre><code class=\"kotlin\">fun request(request: Request, completion: (Response) -> Unit) {         this.completion = completion         val responseReader = ResponseReader().apply { this.responseListener = this@HttpEngine }         val urlSession =             NSURLSession.sessionWithConfiguration(                 NSURLSessionConfiguration.defaultSessionConfiguration, responseReader,                 delegateQueue = NSOperationQueue.currentQueue()             )          val urlRequest =             NSMutableURLRequest(NSURL.URLWithString(request.url)!!).apply {                 setAllHTTPHeaderFields(request.headers)                 setHTTPMethod(request.method.value)                 setCachePolicy(NSURLRequestReloadIgnoringCacheData)              }          fun doRequest() {             val task = urlSession.dataTaskWithRequest(urlRequest)             task?.resume()         }          background{             doRequest()         }     }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043e\u043a \u043c\u0435\u043d\u044f\u0435\u043c AtomicReference \u043d\u0430 FreezableAtomicReference:<\/p>\n<pre><code class=\"kotlin\">\/* internal fun &lt;T> T.atomic(): AtomicReference&lt;T>{     return AtomicReference(this.share()) }*\/  internal fun &lt;T> T.atomic(): FreezableAtomicReference&lt;T>{     return FreezableAtomicReference(this) }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434, \u0433\u0434\u0435 \u043c\u044b \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\"> private fun updateChunks(data: NSData) {         var newValue = ByteArray(0)         newValue += chunks.value         newValue += data.toByteArray()         chunks.value = newValue\/\/.share()     }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0442\u0430\u043a \u0438 \u0434\u044b\u0448\u0438\u0442 \u0447\u0438\u0441\u0442\u043e\u0442\u043e\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043b\u0435\u0442\u0430\u0435\u0442, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e GC (\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">\u0431\u043e\u043b\u0438<\/a>) \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0442\u044e\u043d\u0438\u043d\u0433\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438:<\/p>\n<pre><code class=\"kotlin\">val uiDispatcher: CoroutineContext = Dispatchers.Main val ioDispatcher: CoroutineContext = Dispatchers.Default<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u0430\u0433\u0438\u044e GlobalQueue, \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c ioDispatcher:<\/p>\n<pre><code class=\"swift\"> \/\/output StandaloneCoroutine{Active}@26dbcd0, DarwinGlobalQueueDispatcher@28ea470<\/code><\/pre>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Flow \u0438\/\u0438\u043b\u0438 Channel:<\/p>\n<pre><code class=\"kotlin\">class FlowResponseReader : NSObject(),     NSURLSessionDataDelegateProtocol {     private var chunksFlow = MutableStateFlow(ByteArray(0))     private var rawResponse = CompletableDeferred&lt;Response>()      suspend fun awaitResponse(): Response {         var chunks = ByteArray(0)          chunksFlow.onEach {             chunks += it         }.launchIn(scope)         val response = rawResponse.await()         response.content = chunks.string()         return response     }     \/***\/      private fun updateChunks(data: NSData) {         val bytes = data.toByteArray()         chunksFlow.tryEmit(bytes)     } }<\/code><\/pre>\n<p> \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e.  \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c main thread:<\/p>\n<pre><code class=\"kotlin\">actual override suspend fun request(request: Request):Response {          val response = engine.request(request)         return withContext(uiDispatcher){response}     }<\/code><\/pre>\n<p><em>\u0412\u0430\u0436\u043d\u043e! \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0443\u0442\u0435\u0447\u0435\u043a \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435  iOS, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Swift\/ObjC, \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0436\u0435\u043d\u0438\u044f GC \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0431\u043b\u043e\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0432  autoreleasepool.<\/em> <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430 MainScope, \u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e newSingleThreadContext \u0443\u043a\u0430\u0436\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\"> val task = urlSession.dataTaskWithRequest(urlRequest)         mainScope.launch(newSingleThreadContext(\"MyOwnThread\")) {           print(\"${this.coroutineContext}\")             task?.resume()         } \/\/output  [StandaloneCoroutine{Active}@384d2a0, WorkerDispatcher@384d630]<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u0435\u0437 \u0437\u0430\u043f\u0438\u043d\u043e\u043a. \u0421 \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043b\u0435\u0447 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u043a\u043e\u0440\u043e \u0441\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0433\u043e\u0440\u0430 \u0437\u0430\u0431\u043e\u0442. <br \/>\u041d\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0436\u0438\u0440\u043d\u043e\u0435 &#171;\u041d\u041e&#187;. \u041d\u0435 \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 KMM, \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e\u0432\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443 \u043a \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 InvalidMutabilityException \u0438\u043b\u0438 FreezingException.<br \/>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0441 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 1.6.0-M1-139 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0443:<\/p>\n<pre><code class=\"kotlin\">\/\/gradle.properties kotlin.native.binary.freezing=disabled  \/\/\u043b\u0438\u0431\u043e build.gradle.kts kotlin.targets.withType(KotlinNativeTarget::class.java) {     binaries.all {         binaryOptions[\"freezing\"] = \"disabled\"     } } <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/JetBrains\/kotlin\/blob\/master\/kotlin-native\/NEW_MM.md<\/a><\/p>\n<p>\u0418 \u0441\u044d\u043c\u043f\u043b \u043d\u0430 \u043a\u043e\u043b\u0435\u043d\u043a\u0435: <br \/><a href=\"https:\/\/github.com\/anioutkazharkova\/kotlin_native_network_client\/tree\/feature\/1.6-kn\/sample\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/anioutkazharkova\/kotlin_native_network_client\/tree\/feature\/1.6-kn\/sample<\/a><\/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\/578716\/\"> https:\/\/habr.com\/ru\/articles\/578716\/<\/a><br \/><\/br><\/br><\/p>\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-395963","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/395963","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=395963"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/395963\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=395963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=395963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=395963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}