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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yutaro Muta
November 28, 2025
Technology
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift Concurrencyでのスケジュール処理を考える / Mobile Act OSAKA 17
Mobile Act OSAKA 17
https://mobileact.connpass.com/event/374447/
Yutaro Muta
November 28, 2025
More Decks by Yutaro Muta
See All by Yutaro Muta
Google Nest CamとApple Vision frameworkと猫🐈🐈⬛ / onishi50
yutailang0119
0
230
SwiftUI Inspectorが難しすぎる / Mobile Act OSAKA 18
yutailang0119
0
130
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
440
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
330
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
350
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.6k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
1.1k
バックポートして学ぶ新APIの仕組み
yutailang0119
0
3.4k
Backport AsyncImage
yutailang0119
0
810
Other Decks in Technology
See All in Technology
トークン最適化のためのユーザーストーリー分析 / User Story Analysis for Token Optimization
oomatomo
0
160
Claude Codeとハーネスについて考えてみる
oikon48
16
7.6k
金融の未来を考える / Thinking About the Future of Finance
ks91
PRO
0
150
知見・人・API・DB・予算 ─ ナイナイ尽くしだった人事データ整備 with dbt、5年間の学び
ken6377
1
150
HookでSAST、CIでSAST、SCAでどうにかしている話 / layered-security-for-ai-written-code-with-sast-and-sca
yamaguchitk333
0
110
Docker Desktop不要の時代が来る? WSL標準の「wslc」で Linuxコンテナを動かしてみた.
ueponx
0
630
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
140
Why is RC4 still being used?
tamaiyutaro
0
280
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
360
事業価値を⽣み出すSREへ SREが担うべき意思決定の5層
kenta_hi
0
140
インフラ寄りSREでも 開発に踏み出せる〜境界を越えてユーザー体験に向き合いたい〜
sansantech
PRO
0
180
Terraform 101 (初心者向け) 資料
shuadachi
0
170
Featured
See All Featured
From π to Pie charts
rasagy
0
230
Music & Morning Musume
bryan
47
7.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
We Are The Robots
honzajavorek
0
260
Embracing the Ebb and Flow
colly
88
5.1k
Raft: Consensus for Rubyists
vanstee
141
7.6k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
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) 処理を紹介