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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yutaro Muta
November 28, 2025
Technology
150
0
Share
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
170
SwiftUI Inspectorが難しすぎる / Mobile Act OSAKA 18
yutailang0119
0
100
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
410
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
310
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
340
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.3k
Backport AsyncImage
yutailang0119
0
810
Other Decks in Technology
See All in Technology
AIコーディングエージェントの活用で、コードは静かに肥大化した
yosukeshinoda
1
340
キャリア25年目にしてTypeScript に出会うまで - 「型」を通じて振り返るプログラミング言語遍歴 / Meeting TypeScript After 25 Years in Tech - Looking Back at My Programming Language Journey Through "Types"
bitkey
PRO
2
270
その英語学習、AWSで代替できませんか?
suzutatsu
1
230
GitHub Copilot のこれまでとこれから: From Copilot to Collaborative Agents
yuriemori
1
160
Claude Codeですべての日常業務を爆速化しよう!
minorun365
PRO
14
11k
GitHub Copilot CLI で考える複数エージェント設計
tomokusaba
0
170
「使われるデータ基盤」を目指してデータアナリストとワークショップをやった話
jackojacko_
2
850
まだ道半ば、AI-DLCを歩み始めている話
news_it_enj
2
170
Copilot CLI・IDE・Web・スマホで途切れない開発フローを目指して / One Copilot flow - CLI IDE Web Mobile
aeonpeople
1
980
データ分析基盤の信頼を支える視点と設計
yuki_saito
1
630
エンジニアは生成AIと どのように向き合うべきか? ことばの意味という観点から
verypluming
1
120
TSKaigi 2026 - 10秒のビルドを1秒へ:tsdownが切り拓く2026年のTypeScriptライブラリ開発
teamlab
PRO
2
250
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
210
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
170
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
150
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
280
We Have a Design System, Now What?
morganepeng
55
8.1k
Become a Pro
speakerdeck
PRO
31
5.9k
Fireside Chat
paigeccino
42
3.9k
Ethics towards AI in product and experience design
skipperchong
2
280
Navigating Weather and Climate Data
rabernat
0
200
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
270
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
250
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
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) 処理を紹介