transistorsoft / capacitor-background-fetch

Periodic callbacks in the background for both IOS and Android
78 stars 9 forks source link

Question: can timeout handling be async? #24

Closed gryphonmyers closed 11 months ago

gryphonmyers commented 11 months ago

In the docs, the following example is given:

    const status = await BackgroundFetch.configure({
      minimumFetchInterval: 15
    }, async (taskId) => {
      console.log('[BackgroundFetch] EVENT:', taskId);
      // Perform your work in an awaited Promise
      const result = await this.performYourWorkHere();
      console.log('[BackgroundFetch] work complete:', result);
      // [REQUIRED] Signal to the OS that your work is complete.
      BackgroundFetch.finish(taskId);
    }, async (taskId) => {
      // The OS has signalled that your remaining background-time has expired.
      // You must immediately complete your work and signal #finish.
      console.log('[BackgroundFetch] TIMEOUT:', taskId);
      // [REQUIRED] Signal to the OS that your work is complete.
      BackgroundFetch.finish(taskId);
    });

The third argument, the timeout handler, is an async function, but the comment indicates that I must complete my work "immediately," and the only operation performed in this example is a console.log (synchronous). I'm a bit confused as to whether I can perform async cleanup work in this handler. If so, what are the implications of delay here?

christocracy commented 11 months ago

Probably, but you better get your work done fast and don’t expect an http request to work.