1# @arkts.utils (ArkTS Utils)
2
3The Utils module provides a variety of ArkTS utility functions.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { ArkTSUtils } from '@kit.ArkTS'
13```
14
15## ArkTSUtils.locks
16
17To avoid data races between concurrent instances, the ArkTS common library introduces **AsyncLock**. Passing **AsyncLock** objects by reference across concurrent instances is supported.
18
19ArkTS supports asynchronous operations, and blocking locks are prone to deadlocks. Therefore, only asynchronous locks (non-blocking locks) are used in ArkTS.
20
21The method that uses an asynchronous lock must be marked as **async**, and the caller must use **await** in the call to ensure the correct call sequence. As a result, all outer functions are marked as **async**.
22
23### AsyncLockCallback
24
25type AsyncLockCallback\<T> = () => T | Promise\<T>
26
27A supplementary type alias that represents the callback in all the overloads of [lockAsync](#lockasync).
28
29**Atomic service API**: This API can be used in atomic services since API version 12.
30
31**System capability**: SystemCapability.Utils.Lang
32
33### AsyncLock
34
35A class that implements an asynchronous lock and allows asynchronous operations to be performed under a lock.
36
37#### Attributes
38
39**Atomic service API**: This API can be used in atomic services since API version 12.
40
41**System capability**: SystemCapability.Utils.Lang
42
43| Name| Type  | Readable| Writable| Description      |
44| ---- | ------ | ---- | ---- | ---------- |
45| name | string | Yes  | No  | Name of the lock.|
46
47**Example**
48
49```ts
50// Example 1
51@Sendable
52class A {
53  count_: number = 0;
54  async getCount(): Promise<number> {
55    let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request("lock_1");
56    return lock.lockAsync(() => {
57      return this.count_;
58    })
59  }
60  async setCount(count: number) {
61    let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request("lock_1");
62    await lock.lockAsync(() => {
63      this.count_ = count;
64    })
65  }
66}
67
68// Example 2
69@Sendable
70class A {
71  count_: number = 0;
72  lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock();
73  async getCount(): Promise<number> {
74    return this.lock_.lockAsync(() => {
75      return this.count_;
76    })
77  }
78  async setCount(count: number) {
79    await this.lock_.lockAsync(() => {
80      this.count_ = count;
81    })
82  }
83}
84
85@Concurrent
86async function foo(a: A) {
87  await a.setCount(10)
88}
89```
90
91#### constructor
92
93constructor()
94
95Default constructor used to create an asynchronous lock.
96
97**Atomic service API**: This API can be used in atomic services since API version 12.
98
99**System capability**: SystemCapability.Utils.Lang
100
101**Return value**
102
103| Type                   | Description              |
104| ----------------------- | ------------------ |
105| [AsyncLock](#asynclock) | **AsyncLock** instance created.|
106
107**Example**
108
109```ts
110let lock = new ArkTSUtils.locks.AsyncLock();
111```
112
113#### request
114
115static request(name: string): AsyncLock
116
117Finds or creates (if not found) an **AsyncLock** instance with the specified name.
118
119**Atomic service API**: This API can be used in atomic services since API version 12.
120
121**System capability**: SystemCapability.Utils.Lang
122
123**Parameters**
124
125| Name| Type  | Mandatory| Description                            |
126| ---- | ------ | ---- | -------------------------------- |
127| name | string | Yes  | Name of the lock.|
128
129**Return value**
130
131| Type                   | Description                            |
132| ----------------------- | -------------------------------- |
133| [AsyncLock](#asynclock) | **AsyncLock** instance found or created.|
134
135**Example**
136
137```ts
138let lockName = 'isAvailableLock';
139let lock = ArkTSUtils.locks.AsyncLock.request(lockName);
140```
141
142#### query
143
144static query(name: string): AsyncLockState
145
146Queries information about an asynchronous lock.
147
148**Atomic service API**: This API can be used in atomic services since API version 12.
149
150**System capability**: SystemCapability.Utils.Lang
151
152**Parameters**
153
154| Name| Type  | Mandatory| Description      |
155| ---- | ------ | ---- | ---------- |
156| name | string | Yes  | Name of the lock.|
157
158**Return value**
159
160| Type                             | Description                              |
161| --------------------------------- | ---------------------------------- |
162| [AsyncLockState](#asynclockstate) | **AsyncLockState** instance that contains the lock state information.|
163
164**Error codes**
165
166For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
167
168| ID| Error Message     |
169| -------- | ------------- |
170| 10200030 | The lock does not exist. |
171
172**Example**
173
174```ts
175// You have created a lock somewhere else.
176// let lock = ArkTSUtils.locks.AsyncLock.request("queryTestLock");
177let state = ArkTSUtils.locks.AsyncLock.query('queryTestLock');
178if (!state) {
179    throw new Error('Test failed: A valid state is expected, but the obtained state is '+ state);
180}
181let pending: ArkTSUtils.locks.AsyncLockInfo[] = state.pending;
182let held: ArkTSUtils.locks.AsyncLockInfo[] = state.held;
183```
184
185#### queryAll
186
187static queryAll(): AsyncLockState[]
188
189Queries information about all existing asynchronous locks.
190
191**Atomic service API**: This API can be used in atomic services since API version 12.
192
193**System capability**: SystemCapability.Utils.Lang
194
195**Return value**
196
197| Type                               | Description                            |
198| ----------------------------------- | -------------------------------- |
199| [AsyncLockState](#asynclockstate)[] | **AsyncLockState** array that contains the lock state information.|
200
201**Example**
202
203```ts
204let states: ArkTSUtils.locks.AsyncLockState[] = ArkTSUtils.locks.AsyncLock.queryAll();
205if (states.length == 0) {
206    throw new Error('Test failed: At least one state is expected, but what got is ' + states.length);
207}
208```
209
210#### lockAsync
211
212lockAsync\<T>(callback: AsyncLockCallback\<T>): Promise\<T>
213
214Performs an operation exclusively under a lock. This API acquires the lock, executes the callback, and releases the lock. The callback is executed asynchronously in the same thread where [lockAsync](#lockasync) was called.
215
216**Atomic service API**: This API can be used in atomic services since API version 12.
217
218**System capability**: SystemCapability.Utils.Lang
219
220**Parameters**
221
222| Name    | Type                                   | Mandatory| Description                  |
223| -------- | --------------------------------------- | ---- | ---------------------- |
224| callback | [AsyncLockCallback](#asynclockcallback) | Yes  | Callback to be executed after a lock is acquired.|
225
226**Return value**
227
228| Type       | Description                       |
229| ----------- | --------------------------- |
230| Promise\<T> | Promise that will be resolved after the callback is executed.|
231
232**Error codes**
233
234For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
235
236| ID| Error Message     |
237| -------- | ------------- |
238| 10200030 | The lock does not exist. |
239
240**Example**
241
242```ts
243let lock = new ArkTSUtils.locks.AsyncLock();
244let p1 = lock.lockAsync<void>(() => {
245    // Perform an operation.
246});
247```
248
249#### lockAsync
250
251lockAsync\<T>(callback: AsyncLockCallback\<T>, mode: AsyncLockMode): Promise\<T>
252
253Performs an operation under a lock. This API acquires the lock, executes the callback, and releases the lock. The callback is executed asynchronously in the same thread where [lockAsync](#lockasync) was called.
254
255**Atomic service API**: This API can be used in atomic services since API version 12.
256
257**System capability**: SystemCapability.Utils.Lang
258
259**Parameters**
260
261| Name    | Type                                   | Mandatory| Description                  |
262| -------- | --------------------------------------- | ---- | ---------------------- |
263| callback | [AsyncLockCallback](#asynclockcallback) | Yes  | Callback to be executed after a lock is acquired.|
264| mode     | [AsyncLockMode](#asynclockmode)         | Yes  | Mode of the lock.        |
265
266**Return value**
267
268| Type       | Description                       |
269| ----------- | --------------------------- |
270| Promise\<T> | Promise that will be resolved after the callback is executed.|
271
272**Error codes**
273
274For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
275
276| ID| Error Message     |
277| -------- | ------------- |
278| 10200030 | The lock does not exist. |
279
280**Example**
281
282```ts
283let lock = new ArkTSUtils.locks.AsyncLock();
284let p1 = lock.lockAsync<void>(() => {
285    // Perform an operation.
286}, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE);
287```
288
289#### lockAsync
290
291lockAsync\<T, U>(callback: AsyncLockCallback\<T>, mode: AsyncLockMode, options: AsyncLockOptions\<U>): Promise\<T | U>
292
293Performs an operation under a lock. This API acquires the lock, executes the callback, and releases the lock. The callback is executed asynchronously in the same thread where [lockAsync](#lockasync) was called. An optional timeout value can be provided in [AsyncLockOptions](#asynclockoptions). If a lock is not acquired before timeout, **lockAsync** returns a projected Promise with a **BusinessError** instance. In this instance, the error message contains information about the locks being held and in the waiting state, as well as possible deadlock warnings.
294
295**Atomic service API**: This API can be used in atomic services since API version 12.
296
297**System capability**: SystemCapability.Utils.Lang
298
299**Parameters**
300
301| Name    | Type                                     | Mandatory| Description                  |
302| -------- | ----------------------------------------- | ---- | ---------------------- |
303| callback | [AsyncLockCallback](#asynclockcallback)   | Yes  | Callback to be executed after a lock is acquired.|
304| mode     | [AsyncLockMode](#asynclockmode)           | Yes  | Mode of the lock.        |
305| options  | [AsyncLockOptions\<U>](#asynclockoptions) | Yes  | Options of the lock.        |
306
307**Return value**
308
309| Type            | Description                                              |
310| ---------------- | -------------------------------------------------- |
311| Promise\<T \| U> | Promise that will be resolved after the callback is executed, or rejected in the case of timeout.|
312
313**Error codes**
314
315For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
316
317| ID| Error Message         |
318| -------- | ----------------- |
319| 10200030 | The lock does not exist.     |
320| 10200031 | Timeout exceeded. |
321
322**Example**
323
324```ts
325let lock = new ArkTSUtils.locks.AsyncLock();
326let options = new ArkTSUtils.locks.AsyncLockOptions<void>();
327options.timeout = 1000;
328let p: Promise<void> = lock.lockAsync<void, void>(
329    () => {
330        // Perform an operation.
331    },
332    ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE,
333    options
334);
335```
336
337### AsyncLockMode
338
339Enumerates the modes of an asynchronous lock.
340
341**Atomic service API**: This API can be used in atomic services since API version 12.
342
343**System capability**: SystemCapability.Utils.Lang
344
345| Name     | Value | Description                                                    |
346| --------- | --- | -------------------------------------------------------- |
347| SHARED    | 1   | Shared lock mode, in which multiple threads can run at the same time.  |
348| EXCLUSIVE | 2   | Exclusive lock mode, in which a thread can run only when it exclusively acquires the lock.|
349
350**Example**
351
352```ts
353let lock = new ArkTSUtils.locks.AsyncLock();
354// shared0 can acquire the lock and start execution.
355lock.lockAsync(async () => {
356    console.log('shared0');
357    await new Promise<void>((resolve) => setTimeout(resolve, 1000));
358}, ArkTSUtils.locks.AsyncLockMode.SHARED);
359// shared1 can acquire the lock and start execution without waiting for shared0.
360lock.lockAsync(async () => {
361    console.log('shared1');
362    await new Promise<void>((resolve) => setTimeout(resolve, 1000));
363}, ArkTSUtils.locks.AsyncLockMode.SHARED);
364// exclusive0 can acquire the lock and start execution after shared0 and shared1 are executed.
365lock.lockAsync(async () => {
366    console.log('exclusive0');
367    await new Promise<void>((resolve) => setTimeout(resolve, 1000));
368}, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE);
369// shared2 can acquire the lock and start execution after exclusive0 is executed.
370lock.lockAsync(async () => {
371    console.log('shared2');
372    await new Promise<void>((resolve) => setTimeout(resolve, 1000));
373}, ArkTSUtils.locks.AsyncLockMode.SHARED);
374// shared3 can acquire the lock and start execution after exclusive0 is executed, but not after shared2 is executed.
375lock.lockAsync(async () => {
376    console.log('shared3');
377    await new Promise<void>((resolve) => setTimeout(resolve, 1000));
378}, ArkTSUtils.locks.AsyncLockMode.SHARED);
379```
380
381### AsyncLockOptions
382
383class AsyncLockOptions\<T>
384
385Class that implements the asynchronous lock options.
386
387**Atomic service API**: This API can be used in atomic services since API version 12.
388
389**System capability**: SystemCapability.Utils.Lang
390
391#### constructor
392
393constructor()
394
395Default constructor used to create an **AsyncLockOptions** instance with the default values for all attributes.
396
397**Atomic service API**: This API can be used in atomic services since API version 12.
398
399**System capability**: SystemCapability.Utils.Lang
400
401**Return value**
402
403| Type                                 | Description                  |
404| ------------------------------------- | ---------------------- |
405| [AsyncLockOptions](#asynclockoptions) | **AsyncLockOptions** instance created.|
406
407**Example**
408
409```ts
410let s: ArkTSUtils.locks.AbortSignal<string> = { aborted: false, reason: 'Aborted' };
411let options = new ArkTSUtils.locks.AsyncLockOptions<string>();
412options.isAvailable = false;
413options.signal = s;
414```
415
416#### Attributes
417
418| Name       | Type                                 | Readable| Writable| Description                                                                                                                     |
419| ----------- | ------------------------------------- | ---- | ---- | ------------------------------------------------------------------------------------------------------------------------- |
420| isAvailable | boolean                               | Yes  | Yes  | Whether the lock is available. If the value is **true**, a lock is granted only when it is not held. If the value is **false**, a lock is granted once it is released. The default value is **false**.|
421| signal      | [AbortSignal\<T>](#abortsignal)\|null | Yes  | Yes  | Signal used to abort an asynchronous operation. If **signal.aborted** is **true**, the lock request is discarded. If **signal.aborted** is **null**, the request is queued normally. The default value is **null**.              |
422| timeout     | number                                | Yes  | Yes  | Timeout interval of the lock request, in milliseconds. If the value is greater than zero and a lock is not acquired before time, [lockAsync](#lockasync) returns a rejected Promise. The default value is **0**.     |
423
424### AsyncLockState
425
426A class used to store information about all lock operations currently performed on an **AsyncLock** instance.
427
428**Atomic service API**: This API can be used in atomic services since API version 12.
429
430**System capability**: SystemCapability.Utils.Lang
431
432#### Attributes
433
434| Name   | Type                             | Readable| Writable| Description            |
435| ------- | --------------------------------- | ---- | ---- | ---------------- |
436| held    | [AsyncLockInfo[]](#asynclockinfo) | Yes  | Yes  | Information about the lock being held.  |
437| pending | [AsyncLockInfo[]](#asynclockinfo) | Yes  | Yes  | Information about the lock in the waiting state.|
438
439### AsyncLockInfo
440
441Describes the information about a lock.
442
443**Atomic service API**: This API can be used in atomic services since API version 12.
444
445**System capability**: SystemCapability.Utils.Lang
446
447#### Attributes
448
449| Name     | Type                           | Readable| Writable| Description                                                     |
450| --------- | ------------------------------- | ---- | ---- | --------------------------------------------------------- |
451| name      | string                          | Yes  | Yes  | Name of the lock.                                               |
452| mode      | [AsyncLockMode](#asynclockmode) | Yes  | Yes  | Mode of the lock.                                               |
453| contextId | number                          | Yes  | Yes  | Context identifier of the caller of [AsyncLockMode](#asynclockmode).|
454
455### AbortSignal
456
457A class that implements a signal used to abort an asynchronous operation. An instance of this class must be accessed in the same thread it creates. Otherwise, undefined behavior occurs.
458
459**Atomic service API**: This API can be used in atomic services since API version 12.
460
461**System capability**: SystemCapability.Utils.Lang
462
463#### Attributes
464
465| Name   | Type   | Readable| Writable| Description                                                            |
466| ------- | ------- | ---- | ---- | ---------------------------------------------------------------- |
467| aborted | boolean | Yes  | Yes  | Whether to abort the operation. The value **true** means to abort the operation, and **false** means the opposite.                                          |
468| reason  | \<T>    | Yes  | Yes  | Reason for abort. This value will be used in the rejected Promise returned by [lockAsync](#lockasync).|
469
470## ArkTSUtils.ASON
471
472A utility class used to parse JSON strings into [sendable data](../../arkts-utils/arkts-sendable.md#sendable-data-types). ASON allows you to parse JSON strings and generate data that can be passed across concurrency domains. It also supports conversion from sendable data into JSON strings.
473
474### ISendable
475
476type ISendable = lang.ISendable
477
478**ISendable** is the parent type of all sendable types except null and undefined. It does not have any necessary methods or properties.
479
480**Atomic service API**: This API can be used in atomic services since API version 12.
481
482**System capability**: SystemCapability.Utils.Lang
483
484| Type| Description  |
485| ------ | ------ |
486| [lang.ISendable](js-apis-arkts-lang.md#langisendable)   | Parent type of all sendable types.|
487
488### Transformer
489
490type Transformer = (this: ISendable, key: string, value: ISendable | undefined | null) => ISendable | undefined | null
491
492Defines the type of the conversion result function.
493
494**Atomic service API**: This API can be used in atomic services since API version 12.
495
496**System capability**: SystemCapability.Utils.Lang
497
498**Parameters**
499
500| Name| Type  | Mandatory| Description           |
501| ------ | ------ | ---- | --------------- |
502| this   | [ISendable](#isendable) | Yes| Object to which the key-value pair to parse belongs.|
503| key  | string | Yes| Key to parse.|
504| value  | [ISendable](#isendable) | Yes| Value of the key.|
505
506**Return value**
507
508| Type| Description|
509| -------- | -------- |
510| [ISendable](#isendable) \| undefined \| null | **ISendable** object, undefined, or null.|
511
512### BigIntMode
513
514Enumerates the modes for processing BigInt.
515
516**Atomic service API**: This API can be used in atomic services since API version 12.
517
518**System capability**: SystemCapability.Utils.Lang
519
520| Name| Value| Description           |
521| ------ | ------ | --------------- |
522| DEFAULT   | 0 |BigInt is not supported.|
523| PARSE_AS_BIGINT   | 1 |Parses an integer that is less than -(2^53-1) or greater than (2^53-1) as BigInt.|
524| ALWAYS_PARSE_AS_BIGINT   | 2 |Parses all integers as BigInt.|
525
526### ParseReturnType
527
528Enumerates the return types of the parsing result.
529
530**System capability**: SystemCapability.Utils.Lang
531
532| Name| Value| Description           |
533| ------ | ------ | --------------- |
534| OBJECT   | 0 |Returns a **SendableObject** object.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
535| MAP<sup>13+</sup>   | 1 |Returns a **SendableMap** object.<br>**Atomic service API**: This API can be used in atomic services since API version 13.|
536
537### ParseOptions
538
539Describes the parsing options, which defines the BigInt processing mode and the return type of the parsing result.
540
541**Atomic service API**: This API can be used in atomic services since API version 12.
542
543**System capability**: SystemCapability.Utils.Lang
544
545| Name| Type| Mandatory| Description           |
546| ------ | ------ | ---- | --------------- |
547| bigIntMode   | [BigIntMode](#bigintmode) | Yes|Mode for processing BigInt.|
548| parseReturnType   | [ParseReturnType](#parsereturntype) | Yes|Return type of the parsing result.|
549
550### parse
551
552parse(text: string, reviver?: Transformer, options?: ParseOptions): ISendable | null
553
554Parses a JSON string to generate ISendable data or null.
555
556**Atomic service API**: This API can be used in atomic services since API version 12.
557
558**System capability**: SystemCapability.Utils.Lang
559
560**Parameters**
561
562| Name| Type  | Mandatory| Description           |
563| ------ | ------ | ---- | --------------- |
564| text   | string | Yes| Valid JSON string.|
565| reviver   | [Transformer](#transformer) | No| Conversion function. This parameter can be used to modify the value generated after parsing. The default value is undefined. Currently, only undefined can be passed in.|
566| options   | [ParseOptions](#parseoptions) | No| Parsing options. This parameter is used to control the type of the parsing result. The default value is undefined.|
567
568**Return value**
569
570| Type| Description|
571| -------- | -------- |
572| [ISendable](#isendable) \| null | ISendable data or **null** (if **null** is passed in).|
573
574**Example**
575
576```ts
577import { lang } from '@kit.ArkTS';
578import { collections } from '@kit.ArkTS';
579
580type ISendable = lang.ISendable;
581let jsonText = '{"name": "John", "age": 30, "city": "ChongQing"}';
582let obj = ArkTSUtils.ASON.parse(jsonText) as ISendable;
583console.info((obj as object)?.["name"]);
584// Expected output: 'John'
585console.info((obj as object)?.["age"]);
586// Expected output: 30
587console.info((obj as object)?.["city"]);
588// Expected output: 'ChongQing'
589
590let options: ArkTSUtils.ASON.ParseOptions = {
591  bigIntMode: ArkTSUtils.ASON.BigIntMode.PARSE_AS_BIGINT,
592  parseReturnType: ArkTSUtils.ASON.ParseReturnType.OBJECT,
593}
594let numberText = '{"largeNumber":112233445566778899}';
595let numberObj = ArkTSUtils.ASON.parse(numberText,undefined,options) as ISendable;
596
597console.info((numberObj as object)?.["largeNumber"]);
598// Expected output: 112233445566778899
599
600let options2: ArkTSUtils.ASON.ParseOptions = {
601    bigIntMode: ArkTSUtils.ASON.BigIntMode.PARSE_AS_BIGINT,
602    parseReturnType: ArkTSUtils.ASON.ParseReturnType.MAP,
603  }
604let mapText = '{"largeNumber":112233445566778899}';
605let map  = ArkTSUtils.ASON.parse(mapText,undefined,options2);
606console.info("map is " + map);
607// Expected output: map is [object SendableMap]
608console.info("largeNumber is " + (map as collections.Map<string,bigint>).get("largeNumber"));
609// Expected output: largeNumber is 112233445566778899
610```
611
612### stringify
613
614stringify(value: ISendable | null | undefined): string
615
616Converts ISendable data into a JSON string.
617
618Extension: THis API supports conversion to a JSON string from a Map, Set, [collections.Map](./js-apis-arkts-collections.md#collectionsmap), [collections.Set](./js-apis-arkts-collections.md#collectionsset), [HashMap](./js-apis-hashmap.md#hashmap), or [HashSet](./js-apis-hashset.md#hashset).
619
620**Atomic service API**: This API can be used in atomic services since API version 12.
621
622**System capability**: SystemCapability.Utils.Lang
623
624**Parameters**
625
626| Name| Type| Mandatory| Description|
627| -------- | -------- | -------- | -------- |
628| value | [ISendable](#isendable) \| null \| undefined  | Yes| ISendable data.|
629
630**Return value**
631
632| Type| Description|
633| -------- | -------- |
634| string | JSON string.|
635
636**Example**
637
638```ts
639import { collections, lang, ArkTSUtils } from '@kit.ArkTS';
640
641let arr = new collections.Array(1, 2, 3);
642let str = ArkTSUtils.ASON.stringify(arr);
643console.info(str);
644// Expected output: '[1,2,3]'
645
646let map = new collections.Map<string, string>();
647map.set("key1", "value1");
648map.set("key2", "value2");
649let str2 = ArkTSUtils.ASON.stringify(map);
650console.info(str2);
651// Expected output: '{"key1":"value1","key2":"value2"}'
652
653let set = new Set<number>();
654set.add(1);
655set.add(2);
656set.add(3);
657let str3 = ArkTSUtils.ASON.stringify(set as Object as lang.ISendable);
658console.info(str3);
659// Expected output: '[1,2,3]'
660```
661
662### isSendable
663
664isSendable(value: Object | null | undefined): boolean
665
666Checks whether the passed-in value is of the sendable data type.
667
668**Atomic service API**: This API can be used in atomic services since API version 12.
669
670**System capability**: SystemCapability.Utils.Lang
671
672**Parameters**
673
674| Name| Type| Mandatory| Description|
675| -------- | -------- | -------- | -------- |
676| value | Object \| null \| undefined  | Yes| Object to check.|
677
678**Return value**
679
680| Type| Description|
681| -------- | -------- |
682| boolean | Check result. The value **true** means that the passed-in value is of the sendable data type, and **false** means the opposite.|
683
684**Example**
685
686```ts
687import { ArkTSUtils } from '@kit.ArkTS'
688
689@Sendable
690function sendableFunc() {
691  console.info("sendableFunc")
692}
693
694if (ArkTSUtils.isSendable(sendableFunc)) {
695  console.info("sendableFunc is Sendable");
696} else {
697  console.info("sendableFunc is not Sendable");
698}
699// Expected output: 'SendableFunc is Sendable'
700```
701