Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift Concurrencyでのスケジュール処理を考える / Mobile Act OS...
Search
Yutaro Muta
November 28, 2025
Technology
0
110
Swift Concurrencyでのスケジュール処理を考える / Mobile Act OSAKA 17
Mobile Act OSAKA 17
https://mobileact.connpass.com/event/374447/
Yutaro Muta
November 28, 2025
Tweet
Share
More Decks by Yutaro Muta
See All by Yutaro Muta
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
320
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
240
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
290
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.5k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
1.1k
バックポートして学ぶ新APIの仕組み
yutailang0119
0
3.1k
Backport AsyncImage
yutailang0119
0
770
xcrun Essentials
yutailang0119
6
1.3k
Let's Coding SwiftUI on iPad!
yutailang0119
1
550
Other Decks in Technology
See All in Technology
アラフォーおじさん、はじめてre:Inventに行く / A 40-Something Guy’s First re:Invent Adventure
kaminashi
0
170
TED_modeki_共創ラボ_20251203.pdf
iotcomjpadmin
0
150
ハッカソンから社内プロダクトへ AIエージェント「ko☆shi」開発で学んだ4つの重要要素
sonoda_mj
6
1.7k
2025年のデザインシステムとAI 活用を振り返る
leveragestech
0
340
さくらのクラウド開発ふりかえり2025
kazeburo
2
1.2k
たまに起きる外部サービスの障害に備えたり備えなかったりする話
egmc
0
420
20251219 OpenIDファウンデーション・ジャパン紹介 / OpenID Foundation Japan Intro
oidfj
0
520
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
1
770
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
2.5k
New Relic 1 年生の振り返りと Cloud Cost Intelligence について #NRUG
play_inc
0
250
Claude Skillsの テスト業務での活用事例
moritamasami
1
110
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
2.4k
Featured
See All Featured
Tell your own story through comics
letsgokoyo
0
770
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Practical Orchestrator
shlominoach
190
11k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
130
Reality Check: Gamification 10 Years Later
codingconduct
0
1.9k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Google's AI Overviews - The New Search
badams
0
870
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
410
My Coaching Mixtape
mlcsv
0
13
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
380
Transcript
Swift Concurrencyでの スケジュール処理を考える id:yutailang0119 / @yutailang0119 2025/11/28 Mobile Act Osaka
17 1
yutailang0119 • 株式会社はてな ◦ @京都オフィス ◦ アプリケーションエンジニア ◦ サービスプラットフォームチーム •
try! Swift Tokyo Organizer ◦ 2026チケット販売中 • AVP座談会 🥽 2
3 Swift Concurrencyの スケジュール処理といえば?
4 https://zenn.dev/treastrain/articles/a78b5f892f4654
🔁 Swift Concurrency 時代の 「n秒ごとに処理を実行する」 • AsyncTimerSequence • AsyncStream +
Task.sleep • ... 5
6 「n秒ごとに処理を実行する」 = タスク開始時点で 全ての時機が決まっている
7 今回のお題
今回のお題 8 • タスク⓪後、タスク ①の時機が決まる ◦ タスク①の実行を予約 • タスク①後、タスク ②の時機が決まる
◦ 処理②の実行を予約 • …
9 https://fortee.jp/iosdc-japan-2025/proposal/292e2ec3-d74b-49a6-a8cb-63c2883d589e
Smart Device Management API 10 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦
ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
Smart Device Management API 11 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦
ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
今回のお題 12 • セッション確立後、延長タスク ①の時機が決まる ◦ 延長処理①の実行を予約 • 延長処理①後、延長タスク ②の時機が決まる
◦ 延長処理②の実行を予約 • …
13 今回のお題 「Task終了時に次Taskを予約」
14 TaskScheduler
TaskScheduler 15 actor TaskScheduler { private let task: Task<Void, Error>
init(first: Date?) { task = Task { var _next = first while let next = _next { let interval = max(0, next.timeIntervalSinceNow) try await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000)) try Task.checkCancellation() ... let response = try await client.request(for: request) _next = response.results.expiresAt } } } }
TaskScheduler (汎用化) 16 actor TaskScheduler { private let task: Task<Void,
Error> init(first: Date?, action: @escaping @Sendable () async throws -> Date?) { task = Task { var _next = first while let next = _next { let interval = max(0, next.timeIntervalSinceNow) try await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000)) try Task.checkCancellation() _next = try await action() } } } }
TaskScheduler 17 • Task内部キャンセルはErrorで表現 • 外からのキャンセルも可能にする ◦ task.cancel() ◦ セッションを止めたら、延長予約もキャンセル
• 実際には expiresAt に実行では遅い ◦ expiresAt?.addingTimeInterval(-60)
18 まとめ
まとめ 19 • スケジューリング用途によって手法は異なる ◦ タスク開始時点で全ての時機が決まっている ◦ 処理後に次のタスク実行タイミングが決まる • Swift
ConcurrencyでのScheduler (Worker) 処理を紹介