diff --git a/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md b/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md index d022dd0177356fbbcd1d81031f1b505d009136c6..18a163c13d7d6b249dd0a1a44dbe8978d94edc16 100644 --- a/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md +++ b/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md @@ -4,7 +4,7 @@ The **AbilityDelegatorRegistry** module provides APIs for storing the global reg > **NOTE** > -> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.abilityDelegatorRegistry](js-apis-app-ability-abilityDelegatorRegistry.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-application-abilityManager.md b/en/application-dev/reference/apis/js-apis-application-abilityManager.md index 677884b754c5896b1a6af853d8a4df54355bbb85..6c54d957fae9711c9e48a1f0729e99cea5c532e8 100644 --- a/en/application-dev/reference/apis/js-apis-application-abilityManager.md +++ b/en/application-dev/reference/apis/js-apis-application-abilityManager.md @@ -4,7 +4,7 @@ The **AbilityManager** module provides APIs for obtaining, adding, and modifying > **NOTE** > -> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.abilityManager](js-apis-app-ability-abilityManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are system APIs and cannot be called by third-party applications. ## Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-application-missionManager.md b/en/application-dev/reference/apis/js-apis-application-missionManager.md index 9ad6d14eec8aea3f597e1d7f2b425f29dc0ccc54..fcaa86e787e6ceb9756b58a84ea7c896b33a51e9 100644 --- a/en/application-dev/reference/apis/js-apis-application-missionManager.md +++ b/en/application-dev/reference/apis/js-apis-application-missionManager.md @@ -4,7 +4,7 @@ The **missionManager** module provides APIs to lock, unlock, and clear missions, > **NOTE** > -> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.missionManager](js-apis-app-ability-missionManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-inner-application-context.md b/en/application-dev/reference/apis/js-apis-inner-application-context.md index 492ff93d33f7c4bf6f83776cf2d71be34e50f9c8..e6db9ed5b61837e587762b581a0b97d87c25b366 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-context.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-context.md @@ -40,6 +40,8 @@ Creates the context based on the bundle name. **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + **Parameters** | Name | Type | Mandatory | Description | @@ -102,6 +104,8 @@ Creates the context based on the bundle name and module name. **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + **Parameters** | Name | Type | Mandatory | Description | diff --git a/en/application-dev/reference/apis/js-apis-medialibrary.md b/en/application-dev/reference/apis/js-apis-medialibrary.md index 240108ae1849dfb2fd04d927728c653cdb4627f7..4d8e85aa0ed8ff42dde6b92d6e6a3b9a62caf3fa 100644 --- a/en/application-dev/reference/apis/js-apis-medialibrary.md +++ b/en/application-dev/reference/apis/js-apis-medialibrary.md @@ -77,7 +77,6 @@ let media = mediaLibrary.getMediaLibrary(); ### getFileAssets7+ - getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void Obtains file assets (also called files). This API uses an asynchronous callback to return the result. @@ -105,7 +104,7 @@ async function example() { selectionArgs: [imageType.toString()], }; // Obtain the files in asynchronous callback mode. - media.getFileAssets(imagesFetchOp, (error, fetchFileResult) => { + media.getFileAssets(imagesFetchOp, async (error, fetchFileResult) => { // Check whether the result set of the obtained files is undefined. If yes, the API call fails. if (fetchFileResult == undefined) { console.error('get fetchFileResult failed with error: ' + error); @@ -124,8 +123,8 @@ async function example() { return; } console.info('Get fetchFileResult successfully, count: ' + count); - // Obtain the first file in the result set in asynchronous callback mode. - fetchFileResult.getFirstObject((error, fileAsset) => { + // Obtain the first file in the result set in asynchronous callback mode. If there are a large number of files, use getAllObject instead. + fetchFileResult.getFirstObject(async (error, fileAsset) => { // Check whether the first file is undefined. If yes, the API call fails. if (fileAsset == undefined) { console.error('get first object failed with error: ' + error); @@ -178,7 +177,7 @@ async function example() { selectionArgs: [imageType.toString()], }; // Obtain the files in promise mode. - media.getFileAssets(imagesFetchOp).then((fetchFileResult) => { + media.getFileAssets(imagesFetchOp).then(async (fetchFileResult) => { // Obtain the total number of files in the result set. const count = fetchFileResult.getCount(); // Check whether the number is less than 0. If yes, the API call fails. @@ -192,8 +191,8 @@ async function example() { return; } console.info('Get fetchFileResult successfully, count: ' + count); - // Obtain the first file in the result set in promise mode. - fetchFileResult.getFirstObject().then((fileAsset) => { + // Obtain the first file in the result set in promise mode. If there are a large number of files, use getAllObject instead. + fetchFileResult.getFirstObject().then(async (fileAsset) => { console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName); // Call getNextObject to obtain the next file until the last one. for (let i = 1; i < count; i++) { @@ -514,17 +513,18 @@ Obtains the albums. This API uses an asynchronous callback to return the result. ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => { - if (albumList != undefined) { - console.info('getAlbums successfully: ' + JSON.stringify(albumList)); - } else { - console.error('getAlbums failed with error: ' + error); - } - }) + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => { + if (albumList != undefined) { + console.info('getAlbums successfully: ' + JSON.stringify(albumList)); + } else { + console.error('getAlbums failed with error: ' + error); + } + }) } ``` @@ -554,15 +554,16 @@ Obtains the albums. This API uses a promise to return the result. ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => { - console.info('getAlbums successfully: ' + JSON.stringify(albumList)); - }).catch((error) => { - console.error('getAlbums failed with error: ' + error); - }); + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => { + console.info('getAlbums successfully: ' + JSON.stringify(albumList)); + }).catch((error) => { + console.error('getAlbums failed with error: ' + error); + }); } ``` @@ -2021,7 +2022,7 @@ async function example() { ### getNextObject7+ - getNextObject(callback: AsyncCallback<FileAsset>): void +getNextObject(callback: AsyncCallback<FileAsset>): void Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. > **NOTE** @@ -2049,7 +2050,8 @@ async function example() { }; let fetchFileResult = await media.getFileAssets(getImageOp); let fileAsset = await fetchFileResult.getFirstObject(); - if (!fileAsset.isAfterLast) { + console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName); + if (!fetchFileResult.isAfterLast()) { fetchFileResult.getNextObject((error, fileAsset) => { if (error) { console.error('fetchFileResult getNextObject failed with error: ' + error); @@ -2065,7 +2067,7 @@ async function example() { ### getNextObject7+ - getNextObject(): Promise<FileAsset> +getNextObject(): Promise<FileAsset> Obtains the next file asset in the result set. This API uses a promise to return the result. > **NOTE** @@ -2093,7 +2095,8 @@ async function example() { }; let fetchFileResult = await media.getFileAssets(getImageOp); let fileAsset = await fetchFileResult.getFirstObject(); - if (!fileAsset.isAfterLast) { + console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName); + if (!fetchFileResult.isAfterLast()) { fetchFileResult.getNextObject().then((fileAsset) => { console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName); fetchFileResult.close(); @@ -2369,20 +2372,21 @@ Commits the modification in the album attributes to the database. This API uses ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - const albumList = await media.getAlbums(AlbumNoArgsfetchOp); - const album = albumList[0]; - album.albumName = 'hello'; - album.commitModify((error) => { - if (error) { - console.error('commitModify failed with error: ' + error); - return; - } - console.info('commitModify successful.'); - }) + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + album.albumName = 'hello'; + album.commitModify((error) => { + if (error) { + console.error('commitModify failed with error: ' + error); + return; + } + console.info('commitModify successful.'); + }) } ``` @@ -2406,18 +2410,60 @@ Commits the modification in the album attributes to the database. This API uses ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - const albumList = await media.getAlbums(AlbumNoArgsfetchOp); - const album = albumList[0]; - album.albumName = 'hello'; - album.commitModify().then(() => { - console.info('commitModify successfully'); - }).catch((error) => { - console.error('commitModify failed with error: ' + error); - }); + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + album.albumName = 'hello'; + album.commitModify().then(() => { + console.info('commitModify successfully'); + }).catch((error) => { + console.error('commitModify failed with error: ' + error); + }); +} +``` + +### getFileAssets7+ + +getFileAssets(callback: AsyncCallback<FetchFileResult>): void + +Obtains the file assets in this album. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.READ_MEDIA + +**System capability**: SystemCapability.Multimedia.MediaLibrary.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ----------------------------------- | +| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback used to return the file assets.| + +**Example** + +```js +async function example() { + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + // Obtain the albums that meet the retrieval options and return the album list. + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album. + album.getFileAssets((error, fetchFileResult) => { + if (error) { + console.error('album getFileAssets failed with error: ' + error); + return; + } + let count = fetchFileResult.getCount(); + console.info('album getFileAssets successfully, count: ' + count); + fetchFileResult.close(); + }); } ``` @@ -2442,27 +2488,28 @@ Obtains the file assets in this album. This API uses an asynchronous callback to ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + let fileNoArgsfetchOp = { + selections: '', + selectionArgs: [], + } + // Obtain the albums that meet the retrieval options and return the album list. + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album. + album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => { + if (error) { + console.error('album getFileAssets failed with error: ' + error); + return; } - // Obtain the albums that meet the retrieval options and return the album list. - const albumList = await media.getAlbums(AlbumNoArgsfetchOp); - const album = albumList[0]; - // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album. - album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => { - if (error) { - console.error('album getFileAssets failed with error: ' + error); - return; - } - let count = fetchFileResult.getCount(); - console.info('album getFileAssets successfully, count: ' + count); - fetchFileResult.close(); - }); + let count = fetchFileResult.getCount(); + console.info('album getFileAssets successfully, count: ' + count); + fetchFileResult.close(); + }); } ``` @@ -2492,25 +2539,26 @@ Obtains the file assets in this album. This API uses a promise to return the res ```js async function example() { - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - // Obtain the albums that meet the retrieval options and return the album list. - const albumList = await media.getAlbums(AlbumNoArgsfetchOp); - const album = albumList[0]; - // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album. - album.getFileAssets(fileNoArgsfetchOp).then((fetchFileResult) => { - let count = fetchFileResult.getCount(); - console.info('album getFileAssets successfully, count: ' + count); - fetchFileResult.close(); - }).catch((error) => { - console.error('album getFileAssets failed with error: ' + error); - }); + // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'. + let AlbumNoArgsfetchOp = { + selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?', + selectionArgs:['New Album 1'], + }; + let fileNoArgsfetchOp = { + selections: '', + selectionArgs: [], + }; + // Obtain the albums that meet the retrieval options and return the album list. + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album. + album.getFileAssets(fileNoArgsfetchOp).then((fetchFileResult) => { + let count = fetchFileResult.getCount(); + console.info('album getFileAssets successfully, count: ' + count); + fetchFileResult.close(); + }).catch((error) => { + console.error('album getFileAssets failed with error: ' + error); + }); } ``` diff --git a/en/application-dev/reference/apis/js-apis-taskpool.md b/en/application-dev/reference/apis/js-apis-taskpool.md index 8c40b8ba82dfd4f5d9c30769164d9095600f5945..f347d7e42f1f9901186938a9ae15005d2ed95e6e 100644 --- a/en/application-dev/reference/apis/js-apis-taskpool.md +++ b/en/application-dev/reference/apis/js-apis-taskpool.md @@ -1,4 +1,4 @@ -# @ohos.taskpool (Using the Task Pool) +# @ohos.taskpool (Starting the Task Pool) The task pool provides a multi-thread running environment for applications. It helps reduce resource consumption and improve system performance. It also frees you from caring about the lifecycle of thread instances. You can use the **TaskPool** APIs to create background tasks and perform operations on them, for example, executing or canceling a task. Theoretically, you can create an unlimited number of tasks, but this is not recommended for memory considerations. In addition, you are not advised performing blocking operations in a task, especially indefinite blocking. Long-time blocking operations occupy worker threads and may block other task scheduling, adversely affecting your application performance. @@ -60,12 +60,12 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts @Concurrent -function func(args) { - console.log("func: " + args); +function printArgs(args) { + console.log("printArgs: " + args); return args; } -let task = new taskpool.Task(func, "this is my first Task"); +let task = new taskpool.Task(printArgs, "this is my first Task"); ``` ### Attributes @@ -112,17 +112,17 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts @Concurrent -function func(args) { - console.log("func: " + args); +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { - let value = await taskpool.execute(func, 100); +async function taskpoolExecute() { + let value = await taskpool.execute(printArgs, 100); console.log("taskpool result: " + value); } -taskpoolTest(); +taskpoolExecute(); ``` ## taskpool.execute @@ -135,9 +135,9 @@ Places a task in the internal task queue of the task pool. The task will be dist **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------- | ---- | ---------------------------------------- | -| task | [Task](#task) | Yes | Task to be executed. | +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------------------ | +| task | [Task](#task) | Yes | Task to be executed. | | priority | [Priority](#priority) | No | Priority of the task (not supported yet).| **Return value** @@ -160,18 +160,18 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts @Concurrent -function func(args) { - console.log("func: " + args); +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { - let task = new taskpool.Task(func, 100); +async function taskpoolExecute() { + let task = new taskpool.Task(printArgs, 100); let value = await taskpool.execute(task); console.log("taskpool result: " + value); } -taskpoolTest(); +taskpoolExecute(); ``` ## taskpool.cancel @@ -200,14 +200,14 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco **Example of successful task cancellation** ```ts -function func(args) { - "use concurrent"; - console.log("func: " + args); +@Concurrent +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { - let task = new taskpool.Task(func, 100); +async function taskpoolCancel() { + let task = new taskpool.Task(printArgs, 100); taskpool.execute(task); try { taskpool.cancel(task); @@ -216,20 +216,20 @@ async function taskpoolTest() { } } -taskpoolTest(); +taskpoolCancel(); ``` **Example of a failure to cancel a task that has been executed** ```ts -function func(args) { - "use concurrent"; - console.log("func: " + args); +@Concurrent +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { - let task = new taskpool.Task(func, 100); +async function taskpoolCancel() { + let task = new taskpool.Task(printArgs, 100); let value = taskpool.execute(task); let start = new Date().getTime(); while (new Date().getTime() - start < 1000) {// Wait for 1s to ensure that the task has been executed. @@ -243,25 +243,25 @@ async function taskpoolTest() { } } -taskpoolTest(); +taskpoolCancel(); ``` **Example of a failure to cancel an ongoing task** ```ts -function func(args) { - "use concurrent"; - console.log("func: " + args); +@Concurrent +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { - let task1 = new taskpool.Task(func, 100); - let task2 = new taskpool.Task(func, 200); - let task3 = new taskpool.Task(func, 300); - let task4 = new taskpool.Task(func, 400); - let task5 = new taskpool.Task(func, 500); - let task6 = new taskpool.Task(func, 600); +async function taskpoolCancel() { + let task1 = new taskpool.Task(printArgs, 100); + let task2 = new taskpool.Task(printArgs, 200); + let task3 = new taskpool.Task(printArgs, 300); + let task4 = new taskpool.Task(printArgs, 400); + let task5 = new taskpool.Task(printArgs, 500); + let task6 = new taskpool.Task(printArgs, 600); let res1 = taskpool.execute(task1); let res2 = taskpool.execute(task2); @@ -276,7 +276,7 @@ async function taskpoolTest() { } } -taskpoolTest(); +taskpoolCancel(); ``` ## Additional Information @@ -288,7 +288,7 @@ The following sequenceable data types are supported: All Primitive Type (excludi - The task pool APIs can be used only in the module with **compileMode** set to **esmodule** in the stage model. To check the **compileMode** setting of a module, open the **build-profile.json5** file of the module and check for **"compileMode": "esmodule"** under **buildOption**. - A task in the task pool can reference only variables passed in by input parameters or imported variables, rather than closure variables. The decorator **@Concurrent** is used to intercept unsupported variables. - A task in the task pool supports only common functions or async functions, rather than class member functions or anonymous functions. The decorator **@Concurrent** is used to intercept unsupported functions. -- The decorator **@Concurrent** can be used only in the .ets file. To create a task in the task pool in the .ts file, use the statement **use concurrent**. +- The decorator **@Concurrent** can be used only in .ets files. ### Using the Task Pool in Simple Mode @@ -297,14 +297,14 @@ The following sequenceable data types are supported: All Primitive Type (excludi ```ts // Common functions are supported, and variables passed in by input parameters are also supported. @Concurrent -function func(args) { - console.log("func: " + args); +function printArgs(args) { + console.log("printArgs: " + args); return args; } -async function taskpoolTest() { +async function taskpoolExecute() { // taskpool.execute(task) - let task = new taskpool.Task(func, "create task, then execute"); + let task = new taskpool.Task(printArgs, "create task, then execute"); let val1 = await taskpool.execute(task); console.log("taskpool.execute(task) result: " + val1); @@ -313,7 +313,7 @@ async function taskpoolTest() { console.log("taskpool.execute(function) result: " + val2); } -taskpoolTest(); +taskpoolExecute(); ``` **Example 2** @@ -328,24 +328,24 @@ export var c = 2000; import { c } from "./b"; @Concurrent -function test(a) { +function printArgs(a) { console.log(a); console.log(c); return a; } -async function taskpoolTest() { +async function taskpoolExecute() { // taskpool.execute(task) - let task = new taskpool.Task(test, "create task, then execute"); + let task = new taskpool.Task(printArgs, "create task, then execute"); let val1 = await taskpool.execute(task); console.log("taskpool.execute(task) result: " + val1); // taskpool.execute(function) - let val2 = await taskpool.execute(test, "execute task by func"); + let val2 = await taskpool.execute(printArgs, "execute task by func"); console.log("taskpool.execute(function) result: " + val2); } -taskpoolTest(); +taskpoolExecute(); ``` **Example 3** @@ -353,57 +353,52 @@ taskpoolTest(); ```ts // The async functions are supported. @Concurrent -async function task() { +async function delayExcute() { let ret = await Promise.all([ new Promise(resolve => setTimeout(resolve, 1000, "resolved")) ]); return ret; } -async function taskpoolTest() { - taskpool.execute(task).then((result) => { +async function taskpoolExecute() { + taskpool.execute(delayExcute).then((result) => { console.log("TaskPoolTest task result: " + result); }); } -taskpoolTest(); +taskpoolExecute(); ``` **Example 4** ```ts -// Use use concurrent to create a task in the task pool in the .ts file. -// c.ts -function test1(n) { - "use concurrent" - return n; +// c.ets +@Concurrent +function strSort(inPutArr) { + let newArr = inPutArr.sort(); + return newArr; } -export async function taskpoolTest1() { - console.log("taskpoolTest1 start"); - var task = new taskpool.Task(test1, 100); +export async function func1() { + console.log("taskpoolTest start"); + let strArray = ['c test string', 'b test string', 'a test string']; + var task = new taskpool.Task(strSort, strArray); var result = await taskpool.execute(task); - console.log("taskpoolTest1 result:" + result); + console.log("func1 result:" + result); } -async function test2() { - "use concurrent" - var ret = await Promise.all([ - new Promise(resolve => setTimeout(resolve, 1000, "resolved")) - ]); - return ret; -} -export async function taskpoolTest2() { +export async function func2() { console.log("taskpoolTest2 start"); - taskpool.execute(test2).then((result) => { - console.log("TaskPoolTest2 result: " + result); + let strArray = ['c test string', 'b test string', 'a test string']; + taskpool.execute(strSort, strArray).then((result) => { + console.log("func2 result: " + result); }); } ``` ```ts -/ / a.ets (in the same directory as c.ts) +/ / a.ets (in the same directory as c.ets) import { taskpoolTest1, taskpoolTest2 } from "./c"; -taskpoolTest1(); -taskpoolTest2(); +func1(); +func2(); ```