@@ -23,6 +23,7 @@ import path from 'node:path';
2323import { setTimeout as sleep } from 'node:timers/promises' ;
2424import { flattenIosTree , toIosSelector , writeBase64File , type IosTreeNode } from './snapshot.ts' ;
2525import { normalizeOptionalString } from './strings.ts' ;
26+ import { awaitLimrunOperation } from './request-cancellation.ts' ;
2627import type { LimrunRuntimeDependencies } from './runtime-dependencies.ts' ;
2728
2829export type LimrunIosSession = {
@@ -76,18 +77,32 @@ export async function installLimrunIosApp(
7677 session : LimrunIosSession ,
7778 installablePath : string ,
7879 options ?: ProviderDeviceInstallOptions ,
80+ signal ?: AbortSignal ,
7981) : Promise < ProviderDeviceInstallResult > {
82+ signal ?. throwIfAborted ( ) ;
8083 const prepared = await prepareLimrunIosAsset ( installablePath , session . dependencies ) ;
8184 try {
82- const asset = await limrun . assets . getOrUpload ( {
83- path : prepared . uploadPath ,
84- name : prepared . assetName ,
85- } ) ;
86- const result = await installLimrunIosRemoteApp ( session , asset . signedDownloadUrl , {
87- md5 : asset . md5 ,
88- relaunch : options ?. relaunch ,
89- appIdentifierHint : options ?. appIdentifierHint ,
90- } ) ;
85+ signal ?. throwIfAborted ( ) ;
86+ const asset = await awaitLimrunOperation (
87+ limrun . assets . getOrUpload (
88+ {
89+ path : prepared . uploadPath ,
90+ name : prepared . assetName ,
91+ } ,
92+ { signal } ,
93+ ) ,
94+ signal ,
95+ ) ;
96+ const result = await installLimrunIosRemoteApp (
97+ session ,
98+ asset . signedDownloadUrl ,
99+ {
100+ md5 : asset . md5 ,
101+ relaunch : options ?. relaunch ,
102+ appIdentifierHint : options ?. appIdentifierHint ,
103+ } ,
104+ signal ,
105+ ) ;
91106 const bundleId = result . appId ;
92107 return {
93108 ...( bundleId ? { bundleId, launchTarget : bundleId } : { } ) ,
@@ -102,18 +117,28 @@ export async function installLimrunIosRemoteApp(
102117 session : LimrunIosSession ,
103118 url : string ,
104119 options ?: LimrunIosRemoteInstallOptions ,
120+ signal ?: AbortSignal ,
105121) : Promise < LimrunIosRemoteInstallResult > {
106- const beforeInstallApps = await session . client . listApps ( ) . catch ( ( ) => undefined ) ;
107- const result = await session . client . installApp ( url , {
108- md5 : options ?. md5 ,
109- launchMode : options ?. relaunch ? 'RelaunchIfRunning' : 'ForegroundIfRunning' ,
110- } ) ;
122+ signal ?. throwIfAborted ( ) ;
123+ const beforeInstallApps = await awaitLimrunOperation ( session . client . listApps ( ) , signal ) . catch (
124+ ( error : unknown ) => {
125+ if ( signal ?. aborted ) throw error ;
126+ return undefined ;
127+ } ,
128+ ) ;
129+ const result = await awaitLimrunOperation (
130+ session . client . installApp ( url , {
131+ md5 : options ?. md5 ,
132+ launchMode : options ?. relaunch ? 'RelaunchIfRunning' : 'ForegroundIfRunning' ,
133+ } ) ,
134+ signal ,
135+ ) ;
111136 const resultBundleId = normalizeOptionalString ( result . bundleId ) ;
112137 const requestedBundleId = normalizeOptionalString ( options ?. appIdentifierHint ) ;
113138 let afterInstallApps : LimrunIosApp [ ] = [ ] ;
114139 for ( const delayMs of IOS_APP_INVENTORY_RETRY_DELAYS_MS ) {
115- if ( delayMs > 0 ) await sleep ( delayMs ) ;
116- afterInstallApps = await session . client . listApps ( ) ;
140+ if ( delayMs > 0 ) await sleep ( delayMs , undefined , { signal } ) ;
141+ afterInstallApps = await awaitLimrunOperation ( session . client . listApps ( ) , signal ) ;
117142 const verifiedBundleId = resolveInstalledIosAppId ( {
118143 resultBundleId,
119144 requestedBundleId,
0 commit comments