• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * Defines the basic callback.
18 * @typedef Callback
19 * @syscap SystemCapability.Base
20 * @since 6
21 */
22/**
23 * Defines the basic callback.
24 * @typedef Callback
25 * @syscap SystemCapability.Base
26 * @crossplatform
27 * @since 10
28 */
29export interface Callback<T> {
30  /**
31   * Defines the callback info.
32   * @param { T } data
33   * @syscap SystemCapability.Base
34   * @since 6
35   */
36  /**
37   * Defines the callback info.
38   * @param { T } data
39   * @syscap SystemCapability.Base
40   * @crossplatform
41   * @since 10
42   */
43  (data: T): void;
44}
45
46/**
47 * Defines the basic error callback.
48 * @typedef ErrorCallback
49 * @syscap SystemCapability.Base
50 * @since 6
51 */
52/**
53 * Defines the basic error callback.
54 * @typedef ErrorCallback
55 * @syscap SystemCapability.Base
56 * @crossplatform
57 * @since 10
58 */
59export interface ErrorCallback<T extends Error = BusinessError> {
60  /**
61   * Defines the basic error callback.
62   * @param { T } err
63   * @syscap SystemCapability.Base
64   * @since 6
65   */
66  /**
67   * Defines the basic error callback.
68   * @param { T } err
69   * @syscap SystemCapability.Base
70   * @crossplatform
71   * @since 10
72   */
73  (err: T): void;
74}
75
76/**
77 * Defines the basic async callback.
78 * @typedef AsyncCallback
79 * @syscap SystemCapability.Base
80 * @since 6
81 */
82/**
83 * Defines the basic async callback.
84 * @typedef AsyncCallback
85 * @syscap SystemCapability.Base
86 * @crossplatform
87 * @since 10
88 */
89export interface AsyncCallback<T, E = void> {
90  /**
91   * Defines the callback data.
92   * @param { BusinessError<E> } err
93   * @param { T } data
94   * @syscap SystemCapability.Base
95   * @since 6
96   */
97  /**
98   * Defines the callback data.
99   * @param { BusinessError<E> } err
100   * @param { T } data
101   * @syscap SystemCapability.Base
102   * @crossplatform
103   * @since 10
104   */
105  (err: BusinessError<E>, data: T): void;
106}
107
108/**
109 * Defines the error interface.
110 * @typedef BusinessError
111 * @syscap SystemCapability.Base
112 * @since 6
113 */
114/**
115 * Defines the error interface.
116 * @typedef BusinessError
117 * @syscap SystemCapability.Base
118 * @crossplatform
119 * @since 10
120 */
121export interface BusinessError<T = void> extends Error {
122  /**
123   * Defines the basic error code.
124   * @type { number } code
125   * @syscap SystemCapability.Base
126   * @since 6
127   */
128  /**
129   * Defines the basic error code.
130   * @type { number } code
131   * @syscap SystemCapability.Base
132   * @crossplatform
133   * @since 10
134   */
135  code: number;
136  /**
137   * Defines the additional information for business
138   * @type { ?T } data
139   * @syscap SystemCapability.Base
140   * @since 9
141   */
142  /**
143   * Defines the additional information for business
144   * @type { ?T } data
145   * @syscap SystemCapability.Base
146   * @crossplatform
147   * @since 10
148   */
149  data?: T;
150}
151