expo-task-manager 11.2.0 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 11.3.0 — 2023-06-21
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
18
+
19
+ ### 💡 Others
20
+
21
+ - Update `defineTask` to accept type arguments. ([#21958](https://github.com/expo/expo/pull/21958) by [@kazuma0129](https://github.com/kazuma0129))
22
+
13
23
  ## 11.2.0 — 2023-05-08
14
24
 
15
25
  _This version does not introduce any user-facing changes._
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '11.2.0'
6
+ version = '11.3.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -35,19 +35,11 @@ buildscript {
35
35
  }
36
36
  }
37
37
 
38
- // Creating sources with comments
39
- task androidSourcesJar(type: Jar) {
40
- classifier = 'sources'
41
- from android.sourceSets.main.java.srcDirs
42
- }
43
-
44
38
  afterEvaluate {
45
39
  publishing {
46
40
  publications {
47
41
  release(MavenPublication) {
48
42
  from components.release
49
- // Add additional sourcesJar to artifacts
50
- artifact(androidSourcesJar)
51
43
  }
52
44
  }
53
45
  repositories {
@@ -70,15 +62,21 @@ android {
70
62
  jvmTarget = JavaVersion.VERSION_11.majorVersion
71
63
  }
72
64
 
65
+ namespace "expo.modules.taskManager"
73
66
  defaultConfig {
74
67
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
68
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
76
69
  versionCode 23
77
- versionName "11.2.0"
70
+ versionName "11.3.0"
78
71
  }
79
72
  lintOptions {
80
73
  abortOnError false
81
74
  }
75
+ publishing {
76
+ singleVariant("release") {
77
+ withSourcesJar()
78
+ }
79
+ }
82
80
  }
83
81
 
84
82
  dependencies {
@@ -1,6 +1,4 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="expo.modules.taskManager">
3
-
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
4
2
  <application>
5
3
  <receiver
6
4
  android:name=".TaskBroadcastReceiver"
@@ -9,7 +9,7 @@ export interface TaskManagerError {
9
9
  /**
10
10
  * Represents the object that is passed to the task executor.
11
11
  */
12
- export interface TaskManagerTaskBody<T = object> {
12
+ export interface TaskManagerTaskBody<T = unknown> {
13
13
  /**
14
14
  * An object of data passed to the task executor. Its properties depends on the type of the task.
15
15
  */
@@ -67,7 +67,7 @@ export interface RegisteredTask extends TaskManagerTask {
67
67
  /**
68
68
  * Type of task executor – a function that handles the task.
69
69
  */
70
- export type TaskManagerTaskExecutor = (body: TaskManagerTaskBody) => void;
70
+ export type TaskManagerTaskExecutor<T = unknown> = (body: TaskManagerTaskBody<T>) => void;
71
71
  /**
72
72
  * Defines task function. It must be called in the global scope of your JavaScript bundle.
73
73
  * In particular, it cannot be called in any of React lifecycle methods like `componentDidMount`.
@@ -78,7 +78,7 @@ export type TaskManagerTaskExecutor = (body: TaskManagerTaskBody) => void;
78
78
  * @param taskName Name of the task. It must be the same as the name you provided when registering the task.
79
79
  * @param taskExecutor A function that will be invoked when the task with given `taskName` is executed.
80
80
  */
81
- export declare function defineTask(taskName: string, taskExecutor: TaskManagerTaskExecutor): void;
81
+ export declare function defineTask<T = unknown>(taskName: string, taskExecutor: TaskManagerTaskExecutor<T>): void;
82
82
  /**
83
83
  * Checks whether the task is already defined.
84
84
  *
@@ -1 +1 @@
1
- {"version":3,"file":"TaskManager.d.ts","sourceRoot":"","sources":["../src/TaskManager.ts"],"names":[],"mappings":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,IAAI;gBACF,kBAAkB;gBAClB,MAAM,GAAG,MAAM,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;aAC7D;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,sBAAsB,QAAQ,WAAW,EAAE,KAAK,CAAC,CAAC;aACjE;oBAAS;gBACR,uCAAuC;gBACvC,MAAM,eAAe,CAAC,uBAAuB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;aAC9E;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CACV,sBAAsB,QAAQ,6IAA6I,CAC5K,CAAC;YACF,6DAA6D;YAC7D,MAAM,eAAe,CAAC,uBAAuB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC7E,yFAAyF;YACzF,mGAAmG;YACnG,MAAM,eAAe,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;SACrD;IACH,CAAC,CACF,CAAC;CACH;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,OAAO,MAAM,eAAe,CAAC,gBAAgB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import { EventEmitter, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoTaskManager from './ExpoTaskManager';\n\n// @needsAudit @docsMissing\n/**\n * Error object that can be received through [`TaskManagerTaskBody`](#taskmanagertaskbody) when the\n * task fails.\n */\nexport interface TaskManagerError {\n code: string | number;\n message: string;\n}\n\n// @needsAudit\n/**\n * Represents the object that is passed to the task executor.\n */\nexport interface TaskManagerTaskBody<T = object> {\n /**\n * An object of data passed to the task executor. Its properties depends on the type of the task.\n */\n data: T;\n\n /**\n * Error object if the task failed or `null` otherwise.\n */\n error: TaskManagerError | null;\n\n /**\n * Additional details containing unique ID of task event and name of the task.\n */\n executionInfo: TaskManagerTaskBodyExecutionInfo;\n}\n\n// @needsAudit\n/**\n * Additional details about execution provided in `TaskManagerTaskBody`.\n */\nexport interface TaskManagerTaskBodyExecutionInfo {\n /**\n * State of the application.\n * @platform ios\n */\n appState?: 'active' | 'background' | 'inactive';\n /**\n * Unique ID of task event.\n */\n eventId: string;\n /**\n * Name of the task.\n */\n taskName: string;\n}\n\n// @needsAudit\n/**\n * Represents an already registered task.\n */\nexport interface TaskManagerTask {\n /**\n * Name that the task is registered with.\n */\n taskName: string;\n\n /**\n * Type of the task which depends on how the task was registered.\n */\n taskType: string;\n\n /**\n * Provides `options` that the task was registered with.\n */\n options: any;\n}\n\n/**\n * @deprecated Use `TaskManagerTask` instead.\n * @hidden\n */\nexport interface RegisteredTask extends TaskManagerTask {}\n\n// @needsAudit\n/**\n * Type of task executor – a function that handles the task.\n */\nexport type TaskManagerTaskExecutor = (body: TaskManagerTaskBody) => void;\n\nconst tasks: Map<string, TaskManagerTaskExecutor> = new Map<string, TaskManagerTaskExecutor>();\n\nfunction _validateTaskName(taskName) {\n if (!taskName || typeof taskName !== 'string') {\n throw new TypeError('`taskName` must be a non-empty string.');\n }\n}\n\n// @needsAudit\n/**\n * Defines task function. It must be called in the global scope of your JavaScript bundle.\n * In particular, it cannot be called in any of React lifecycle methods like `componentDidMount`.\n * This limitation is due to the fact that when the application is launched in the background,\n * we need to spin up your JavaScript app, run your task and then shut down — no views are mounted\n * in this scenario.\n *\n * @param taskName Name of the task. It must be the same as the name you provided when registering the task.\n * @param taskExecutor A function that will be invoked when the task with given `taskName` is executed.\n */\nexport function defineTask(taskName: string, taskExecutor: TaskManagerTaskExecutor) {\n if (!taskName || typeof taskName !== 'string') {\n console.warn(`TaskManager.defineTask: 'taskName' argument must be a non-empty string.`);\n return;\n }\n if (!taskExecutor || typeof taskExecutor !== 'function') {\n console.warn(`TaskManager.defineTask: 'task' argument must be a function.`);\n return;\n }\n tasks.set(taskName, taskExecutor);\n}\n\n// @needsAudit\n/**\n * Checks whether the task is already defined.\n *\n * @param taskName Name of the task.\n */\nexport function isTaskDefined(taskName: string): boolean {\n return tasks.has(taskName);\n}\n\n// @needsAudit\n/**\n * Determine whether the task is registered. Registered tasks are stored in a persistent storage and\n * preserved between sessions.\n *\n * @param taskName Name of the task.\n * @returns A promise which fulfills with a `boolean` value whether or not the task with given name\n * is already registered.\n */\nexport async function isTaskRegisteredAsync(taskName: string): Promise<boolean> {\n if (!ExpoTaskManager.isTaskRegisteredAsync) {\n throw new UnavailabilityError('TaskManager', 'isTaskRegisteredAsync');\n }\n\n _validateTaskName(taskName);\n return ExpoTaskManager.isTaskRegisteredAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Retrieves `options` associated with the task, that were passed to the function registering the task\n * (eg. `Location.startLocationUpdatesAsync`).\n *\n * @param taskName Name of the task.\n * @return A promise which fulfills with the `options` object that was passed while registering task\n * with given name or `null` if task couldn't be found.\n */\nexport async function getTaskOptionsAsync<TaskOptions>(taskName: string): Promise<TaskOptions> {\n if (!ExpoTaskManager.getTaskOptionsAsync) {\n throw new UnavailabilityError('TaskManager', 'getTaskOptionsAsync');\n }\n\n _validateTaskName(taskName);\n return ExpoTaskManager.getTaskOptionsAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Provides information about tasks registered in the app.\n *\n * @returns A promise which fulfills with an array of tasks registered in the app. Example:\n * ```json\n * [\n * {\n * taskName: 'location-updates-task-name',\n * taskType: 'location',\n * options: {\n * accuracy: Location.Accuracy.High,\n * showsBackgroundLocationIndicator: false,\n * },\n * },\n * {\n * taskName: 'geofencing-task-name',\n * taskType: 'geofencing',\n * options: {\n * regions: [...],\n * },\n * },\n * ]\n * ```\n */\nexport async function getRegisteredTasksAsync(): Promise<TaskManagerTask[]> {\n if (!ExpoTaskManager.getRegisteredTasksAsync) {\n throw new UnavailabilityError('TaskManager', 'getRegisteredTasksAsync');\n }\n\n return ExpoTaskManager.getRegisteredTasksAsync();\n}\n\n// @needsAudit\n/**\n * Unregisters task from the app, so the app will not be receiving updates for that task anymore.\n * _It is recommended to use methods specialized by modules that registered the task, eg.\n * [`Location.stopLocationUpdatesAsync`](./location/#expolocationstoplocationupdatesasynctaskname)._\n *\n * @param taskName Name of the task to unregister.\n * @return A promise which fulfills as soon as the task is unregistered.\n */\nexport async function unregisterTaskAsync(taskName: string): Promise<void> {\n if (!ExpoTaskManager.unregisterTaskAsync) {\n throw new UnavailabilityError('TaskManager', 'unregisterTaskAsync');\n }\n\n _validateTaskName(taskName);\n await ExpoTaskManager.unregisterTaskAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Unregisters all tasks registered for the running app. You may want to call this when the user is\n * signing out and you no longer need to track his location or run any other background tasks.\n * @return A promise which fulfills as soon as all tasks are completely unregistered.\n */\nexport async function unregisterAllTasksAsync(): Promise<void> {\n if (!ExpoTaskManager.unregisterAllTasksAsync) {\n throw new UnavailabilityError('TaskManager', 'unregisterAllTasksAsync');\n }\n\n await ExpoTaskManager.unregisterAllTasksAsync();\n}\n\nif (ExpoTaskManager) {\n const eventEmitter = new EventEmitter(ExpoTaskManager);\n eventEmitter.addListener<TaskManagerTaskBody>(\n ExpoTaskManager.EVENT_NAME,\n async ({ data, error, executionInfo }) => {\n const { eventId, taskName } = executionInfo;\n const taskExecutor = tasks.get(taskName);\n let result: any = null;\n\n if (taskExecutor) {\n try {\n // Execute JS task\n result = await taskExecutor({ data, error, executionInfo });\n } catch (error) {\n console.error(`TaskManager: Task \"${taskName}\" failed:`, error);\n } finally {\n // Notify manager the task is finished.\n await ExpoTaskManager.notifyTaskFinishedAsync(taskName, { eventId, result });\n }\n } else {\n console.warn(\n `TaskManager: Task \"${taskName}\" has been executed but looks like it is not defined. Please make sure that \"TaskManager.defineTask\" is called during initialization phase.`\n );\n // No tasks defined -> we need to notify about finish anyway.\n await ExpoTaskManager.notifyTaskFinishedAsync(taskName, { eventId, result });\n // We should also unregister such tasks automatically as the task might have been removed\n // from the app or just renamed - in that case it needs to be registered again (with the new name).\n await ExpoTaskManager.unregisterTaskAsync(taskName);\n }\n }\n );\n}\n\n// @needsAudit\n/**\n * Determine if the `TaskManager` API can be used in this app.\n * @return A promise fulfills with `true` if the API can be used, and `false` otherwise.\n * On the web it always returns `false`.\n */\nexport async function isAvailableAsync(): Promise<boolean> {\n return await ExpoTaskManager.isAvailableAsync();\n}\n"]}
1
+ {"version":3,"file":"TaskManager.js","sourceRoot":"","sources":["../src/TaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAsFhD,MAAM,KAAK,GAA8C,IAAI,GAAG,EAG7D,CAAC;AAEJ,SAAS,iBAAiB,CAAC,QAAQ;IACjC,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC7C,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;KAC/D;AACH,CAAC;AAED,cAAc;AACd;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,YAAwC;IAExC,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC7C,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACxF,OAAO;KACR;IACD,IAAI,CAAC,YAAY,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;QAC5E,OAAO;KACR;IACD,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACpC,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,cAAc;AACd;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAgB;IAC1D,IAAI,CAAC,eAAe,CAAC,qBAAqB,EA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,CAAC","sourcesContent":["import { EventEmitter, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoTaskManager from './ExpoTaskManager';\n\n// @needsAudit @docsMissing\n/**\n * Error object that can be received through [`TaskManagerTaskBody`](#taskmanagertaskbody) when the\n * task fails.\n */\nexport interface TaskManagerError {\n code: string | number;\n message: string;\n}\n\n// @needsAudit\n/**\n * Represents the object that is passed to the task executor.\n */\nexport interface TaskManagerTaskBody<T = unknown> {\n /**\n * An object of data passed to the task executor. Its properties depends on the type of the task.\n */\n data: T;\n\n /**\n * Error object if the task failed or `null` otherwise.\n */\n error: TaskManagerError | null;\n\n /**\n * Additional details containing unique ID of task event and name of the task.\n */\n executionInfo: TaskManagerTaskBodyExecutionInfo;\n}\n\n// @needsAudit\n/**\n * Additional details about execution provided in `TaskManagerTaskBody`.\n */\nexport interface TaskManagerTaskBodyExecutionInfo {\n /**\n * State of the application.\n * @platform ios\n */\n appState?: 'active' | 'background' | 'inactive';\n /**\n * Unique ID of task event.\n */\n eventId: string;\n /**\n * Name of the task.\n */\n taskName: string;\n}\n\n// @needsAudit\n/**\n * Represents an already registered task.\n */\nexport interface TaskManagerTask {\n /**\n * Name that the task is registered with.\n */\n taskName: string;\n\n /**\n * Type of the task which depends on how the task was registered.\n */\n taskType: string;\n\n /**\n * Provides `options` that the task was registered with.\n */\n options: any;\n}\n\n/**\n * @deprecated Use `TaskManagerTask` instead.\n * @hidden\n */\nexport interface RegisteredTask extends TaskManagerTask {}\n\n// @needsAudit\n/**\n * Type of task executor – a function that handles the task.\n */\nexport type TaskManagerTaskExecutor<T = unknown> = (body: TaskManagerTaskBody<T>) => void;\n\nconst tasks: Map<string, TaskManagerTaskExecutor<any>> = new Map<\n string,\n TaskManagerTaskExecutor<any>\n>();\n\nfunction _validateTaskName(taskName) {\n if (!taskName || typeof taskName !== 'string') {\n throw new TypeError('`taskName` must be a non-empty string.');\n }\n}\n\n// @needsAudit\n/**\n * Defines task function. It must be called in the global scope of your JavaScript bundle.\n * In particular, it cannot be called in any of React lifecycle methods like `componentDidMount`.\n * This limitation is due to the fact that when the application is launched in the background,\n * we need to spin up your JavaScript app, run your task and then shut down — no views are mounted\n * in this scenario.\n *\n * @param taskName Name of the task. It must be the same as the name you provided when registering the task.\n * @param taskExecutor A function that will be invoked when the task with given `taskName` is executed.\n */\nexport function defineTask<T = unknown>(\n taskName: string,\n taskExecutor: TaskManagerTaskExecutor<T>\n) {\n if (!taskName || typeof taskName !== 'string') {\n console.warn(`TaskManager.defineTask: 'taskName' argument must be a non-empty string.`);\n return;\n }\n if (!taskExecutor || typeof taskExecutor !== 'function') {\n console.warn(`TaskManager.defineTask: 'task' argument must be a function.`);\n return;\n }\n tasks.set(taskName, taskExecutor);\n}\n\n// @needsAudit\n/**\n * Checks whether the task is already defined.\n *\n * @param taskName Name of the task.\n */\nexport function isTaskDefined(taskName: string): boolean {\n return tasks.has(taskName);\n}\n\n// @needsAudit\n/**\n * Determine whether the task is registered. Registered tasks are stored in a persistent storage and\n * preserved between sessions.\n *\n * @param taskName Name of the task.\n * @returns A promise which fulfills with a `boolean` value whether or not the task with given name\n * is already registered.\n */\nexport async function isTaskRegisteredAsync(taskName: string): Promise<boolean> {\n if (!ExpoTaskManager.isTaskRegisteredAsync) {\n throw new UnavailabilityError('TaskManager', 'isTaskRegisteredAsync');\n }\n\n _validateTaskName(taskName);\n return ExpoTaskManager.isTaskRegisteredAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Retrieves `options` associated with the task, that were passed to the function registering the task\n * (eg. `Location.startLocationUpdatesAsync`).\n *\n * @param taskName Name of the task.\n * @return A promise which fulfills with the `options` object that was passed while registering task\n * with given name or `null` if task couldn't be found.\n */\nexport async function getTaskOptionsAsync<TaskOptions>(taskName: string): Promise<TaskOptions> {\n if (!ExpoTaskManager.getTaskOptionsAsync) {\n throw new UnavailabilityError('TaskManager', 'getTaskOptionsAsync');\n }\n\n _validateTaskName(taskName);\n return ExpoTaskManager.getTaskOptionsAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Provides information about tasks registered in the app.\n *\n * @returns A promise which fulfills with an array of tasks registered in the app. Example:\n * ```json\n * [\n * {\n * taskName: 'location-updates-task-name',\n * taskType: 'location',\n * options: {\n * accuracy: Location.Accuracy.High,\n * showsBackgroundLocationIndicator: false,\n * },\n * },\n * {\n * taskName: 'geofencing-task-name',\n * taskType: 'geofencing',\n * options: {\n * regions: [...],\n * },\n * },\n * ]\n * ```\n */\nexport async function getRegisteredTasksAsync(): Promise<TaskManagerTask[]> {\n if (!ExpoTaskManager.getRegisteredTasksAsync) {\n throw new UnavailabilityError('TaskManager', 'getRegisteredTasksAsync');\n }\n\n return ExpoTaskManager.getRegisteredTasksAsync();\n}\n\n// @needsAudit\n/**\n * Unregisters task from the app, so the app will not be receiving updates for that task anymore.\n * _It is recommended to use methods specialized by modules that registered the task, eg.\n * [`Location.stopLocationUpdatesAsync`](./location/#expolocationstoplocationupdatesasynctaskname)._\n *\n * @param taskName Name of the task to unregister.\n * @return A promise which fulfills as soon as the task is unregistered.\n */\nexport async function unregisterTaskAsync(taskName: string): Promise<void> {\n if (!ExpoTaskManager.unregisterTaskAsync) {\n throw new UnavailabilityError('TaskManager', 'unregisterTaskAsync');\n }\n\n _validateTaskName(taskName);\n await ExpoTaskManager.unregisterTaskAsync(taskName);\n}\n\n// @needsAudit\n/**\n * Unregisters all tasks registered for the running app. You may want to call this when the user is\n * signing out and you no longer need to track his location or run any other background tasks.\n * @return A promise which fulfills as soon as all tasks are completely unregistered.\n */\nexport async function unregisterAllTasksAsync(): Promise<void> {\n if (!ExpoTaskManager.unregisterAllTasksAsync) {\n throw new UnavailabilityError('TaskManager', 'unregisterAllTasksAsync');\n }\n\n await ExpoTaskManager.unregisterAllTasksAsync();\n}\n\nif (ExpoTaskManager) {\n const eventEmitter = new EventEmitter(ExpoTaskManager);\n eventEmitter.addListener<TaskManagerTaskBody>(\n ExpoTaskManager.EVENT_NAME,\n async ({ data, error, executionInfo }) => {\n const { eventId, taskName } = executionInfo;\n const taskExecutor = tasks.get(taskName);\n let result: any = null;\n\n if (taskExecutor) {\n try {\n // Execute JS task\n result = await taskExecutor({ data, error, executionInfo });\n } catch (error) {\n console.error(`TaskManager: Task \"${taskName}\" failed:`, error);\n } finally {\n // Notify manager the task is finished.\n await ExpoTaskManager.notifyTaskFinishedAsync(taskName, { eventId, result });\n }\n } else {\n console.warn(\n `TaskManager: Task \"${taskName}\" has been executed but looks like it is not defined. Please make sure that \"TaskManager.defineTask\" is called during initialization phase.`\n );\n // No tasks defined -> we need to notify about finish anyway.\n await ExpoTaskManager.notifyTaskFinishedAsync(taskName, { eventId, result });\n // We should also unregister such tasks automatically as the task might have been removed\n // from the app or just renamed - in that case it needs to be registered again (with the new name).\n await ExpoTaskManager.unregisterTaskAsync(taskName);\n }\n }\n );\n}\n\n// @needsAudit\n/**\n * Determine if the `TaskManager` API can be used in this app.\n * @return A promise fulfills with `true` if the API can be used, and `false` otherwise.\n * On the web it always returns `false`.\n */\nexport async function isAvailableAsync(): Promise<boolean> {\n return await ExpoTaskManager.isAvailableAsync();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-task-manager",
3
- "version": "11.2.0",
3
+ "version": "11.3.0",
4
4
  "description": "Expo module that provides support for tasks that can run in the background.",
5
5
  "main": "build/TaskManager.js",
6
6
  "types": "build/TaskManager.d.ts",
@@ -33,7 +33,7 @@
33
33
  "license": "MIT",
34
34
  "homepage": "https://docs.expo.dev/versions/latest/sdk/task-manager/",
35
35
  "dependencies": {
36
- "unimodules-app-loader": "~4.1.0"
36
+ "unimodules-app-loader": "~4.2.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "expo-module-scripts": "^3.0.0"
@@ -41,5 +41,5 @@
41
41
  "peerDependencies": {
42
42
  "expo": "*"
43
43
  },
44
- "gitHead": "4ba50c428c8369bb6b3a51a860d4898ad4ccbe78"
44
+ "gitHead": "fa5ecca8251986b9f197cc14074eec0ab6dfb6db"
45
45
  }
@@ -16,7 +16,7 @@ export interface TaskManagerError {
16
16
  /**
17
17
  * Represents the object that is passed to the task executor.
18
18
  */
19
- export interface TaskManagerTaskBody<T = object> {
19
+ export interface TaskManagerTaskBody<T = unknown> {
20
20
  /**
21
21
  * An object of data passed to the task executor. Its properties depends on the type of the task.
22
22
  */
@@ -84,9 +84,12 @@ export interface RegisteredTask extends TaskManagerTask {}
84
84
  /**
85
85
  * Type of task executor – a function that handles the task.
86
86
  */
87
- export type TaskManagerTaskExecutor = (body: TaskManagerTaskBody) => void;
87
+ export type TaskManagerTaskExecutor<T = unknown> = (body: TaskManagerTaskBody<T>) => void;
88
88
 
89
- const tasks: Map<string, TaskManagerTaskExecutor> = new Map<string, TaskManagerTaskExecutor>();
89
+ const tasks: Map<string, TaskManagerTaskExecutor<any>> = new Map<
90
+ string,
91
+ TaskManagerTaskExecutor<any>
92
+ >();
90
93
 
91
94
  function _validateTaskName(taskName) {
92
95
  if (!taskName || typeof taskName !== 'string') {
@@ -105,7 +108,10 @@ function _validateTaskName(taskName) {
105
108
  * @param taskName Name of the task. It must be the same as the name you provided when registering the task.
106
109
  * @param taskExecutor A function that will be invoked when the task with given `taskName` is executed.
107
110
  */
108
- export function defineTask(taskName: string, taskExecutor: TaskManagerTaskExecutor) {
111
+ export function defineTask<T = unknown>(
112
+ taskName: string,
113
+ taskExecutor: TaskManagerTaskExecutor<T>
114
+ ) {
109
115
  if (!taskName || typeof taskName !== 'string') {
110
116
  console.warn(`TaskManager.defineTask: 'taskName' argument must be a non-empty string.`);
111
117
  return;