microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/typings/q/Q.d.ts

340lines · modecode

1// Type definitions for Q
2// Project: https://github.com/kriskowal/q
3// Definitions by: Barrie Nemetchek <https://github.com/bnemetchek>, Andrew Gaspar <https://github.com/AndrewGaspar/>, John Reilly <https://github.com/johnnyreilly>
4// Definitions: https://github.com/borisyankov/DefinitelyTyped
5
6/**
7 * If value is a Q promise, returns the promise.
8 * If value is a promise from another library it is coerced into a Q promise (where possible).
9 */
10declare function Q<T>(promise: Q.IPromise<T>): Q.Promise<T>;
11/**
12 * If value is not a promise, returns a promise that is fulfilled with value.
13 */
14declare function Q<T>(value: T): Q.Promise<T>;
15
16declare module Q {
17 interface IPromise<T> {
18 then<U>(onFulfill?: (value: T) => U | IPromise<U>, onReject?: (error: any) => U | IPromise<U>): IPromise<U>;
19 }
20
21 interface Deferred<T> {
22 promise: Promise<T>;
23 resolve(value: T): void;
24 reject(reason: any): void;
25 notify(value: any): void;
26 makeNodeResolver(): (reason: any, value: T) => void;
27 }
28
29 interface Promise<T> {
30 /**
31 * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.
32
33 * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.
34 */
35 fin(finallyCallback: () => any): Promise<T>;
36 /**
37 * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.
38
39 * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.
40 */
41 finally(finallyCallback: () => any): Promise<T>;
42
43 /**
44 * The then method from the Promises/A+ specification, with an additional progress handler.
45 */
46 then<U>(onFulfill?: (value: T) => U | IPromise<U>, onReject?: (error: any) => U | IPromise<U>, onProgress?: Function): Promise<U>;
47
48 /**
49 * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
50 *
51 * This is especially useful in conjunction with all
52 */
53 spread<U>(onFulfill: (...args: any[]) => IPromise<U> | U, onReject?: (reason: any) => IPromise<U> | U): Promise<U>;
54
55 fail<U>(onRejected: (reason: any) => U | IPromise<U>): Promise<U>;
56
57 /**
58 * A sugar method, equivalent to promise.then(undefined, onRejected).
59 */
60 catch<U>(onRejected: (reason: any) => U | IPromise<U>): Promise<U>;
61
62 /**
63 * A sugar method, equivalent to promise.then(undefined, undefined, onProgress).
64 */
65 progress(onProgress: (progress: any) => any): Promise<T>;
66
67 /**
68 * Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop.
69 *
70 * This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object.
71 *
72 * Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn.
73 *
74 * The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it.
75 */
76 done(onFulfilled?: (value: T) => any, onRejected?: (reason: any) => any, onProgress?: (progress: any) => any): void;
77
78 /**
79 * If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason) when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled. If callback is not a function, simply returns promise.
80 */
81 nodeify(callback: (reason: any, value: any) => void): Promise<T>;
82
83 /**
84 * Returns a promise to get the named property of an object. Essentially equivalent to
85 *
86 * promise.then(function (o) {
87 * return o[propertyName];
88 * });
89 */
90 get<U>(propertyName: String): Promise<U>;
91 set<U>(propertyName: String, value: any): Promise<U>;
92 delete<U>(propertyName: String): Promise<U>;
93 /**
94 * Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to
95 *
96 * promise.then(function (o) {
97 * return o[methodName].apply(o, args);
98 * });
99 */
100 post<U>(methodName: String, args: any[]): Promise<U>;
101 /**
102 * Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call.
103 */
104 invoke<U>(methodName: String, ...args: any[]): Promise<U>;
105 fapply<U>(args: any[]): Promise<U>;
106 fcall<U>(...args: any[]): Promise<U>;
107
108 /**
109 * Returns a promise for an array of the property names of an object. Essentially equivalent to
110 *
111 * promise.then(function (o) {
112 * return Object.keys(o);
113 * });
114 */
115 keys(): Promise<string[]>;
116
117 /**
118 * A sugar method, equivalent to promise.then(function () { return value; }).
119 */
120 thenResolve<U>(value: U): Promise<U>;
121 /**
122 * A sugar method, equivalent to promise.then(function () { throw reason; }).
123 */
124 thenReject(reason: any): Promise<T>;
125
126 /**
127 * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler.
128 */
129 tap(onFulfilled: (value: T) => any): Promise<T>;
130
131 timeout(ms: number, message?: string): Promise<T>;
132 /**
133 * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.
134 */
135 delay(ms: number): Promise<T>;
136
137 /**
138 * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.
139 */
140 isFulfilled(): boolean;
141 /**
142 * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.
143 */
144 isRejected(): boolean;
145 /**
146 * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
147 */
148 isPending(): boolean;
149
150 valueOf(): any;
151
152 /**
153 * Returns a "state snapshot" object, which will be in one of three forms:
154 *
155 * - { state: "pending" }
156 * - { state: "fulfilled", value: <fulfllment value> }
157 * - { state: "rejected", reason: <rejection reason> }
158 */
159 inspect(): PromiseState<T>;
160 }
161
162 interface PromiseState<T> {
163 /**
164 * "fulfilled", "rejected", "pending"
165 */
166 state: string;
167 value?: T;
168 reason?: any;
169 }
170
171 // If no value provided, returned promise will be of void type
172 export function when(): Promise<void>;
173
174 // if no fulfill, reject, or progress provided, returned promise will be of same type
175 export function when<T>(value: T | IPromise<T>): Promise<T>;
176
177 // If a non-promise value is provided, it will not reject or progress
178 export function when<T, U>(value: T | IPromise<T>, onFulfilled: (val: T) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>, onProgress?: (progress: any) => any): Promise<U>;
179
180 /**
181 * Currently "impossible" (and I use the term loosely) to implement due to TypeScript limitations as it is now.
182 * See: https://github.com/microsoft/TypeScript/issues/1784 for discussion on it.
183 */
184 // export function try(method: Function, ...args: any[]): Promise<any>;
185
186 export function fbind<T>(method: (...args: any[]) => T | IPromise<T>, ...args: any[]): (...args: any[]) => Promise<T>;
187
188 export function fcall<T>(method: (...args: any[]) => T, ...args: any[]): Promise<T>;
189
190 export function send<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
191 export function invoke<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
192 export function mcall<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
193
194 export function denodeify<T>(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise<T>;
195 export function nbind<T>(nodeFunction: Function, thisArg: any, ...args: any[]): (...args: any[]) => Promise<T>;
196 export function nfbind<T>(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise<T>;
197 export function nfcall<T>(nodeFunction: Function, ...args: any[]): Promise<T>;
198 export function nfapply<T>(nodeFunction: Function, args: any[]): Promise<T>;
199
200 export function ninvoke<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
201 export function npost<T>(nodeModule: any, functionName: string, args: any[]): Promise<T>;
202 export function nsend<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
203 export function nmcall<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
204
205 /**
206 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
207 */
208 export function all<T>(promises: IPromise<T>[]): Promise<T[]>;
209
210 /**
211 * Returns the first resolved promise of an array. Prior rejected promises are ignored. Rejects only if all promises are rejected.
212 */
213 export function any<T>(promises: IPromise<T>[]): Promise<T>;
214
215 /**
216 * Returns a promise for the first of an array of promises to become settled.
217 */
218 export function race<T>(promises: IPromise<T>[]): Promise<T>;
219
220 /**
221 * Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.
222 */
223 export function allSettled<T>(promises: IPromise<T>[]): Promise<PromiseState<T>[]>;
224
225 export function allResolved<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
226
227 /**
228 * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
229 * This is especially useful in conjunction with all.
230 */
231 export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>): Promise<U>;
232
233 /**
234 * Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message is not supplied, the message will be "Timed out after " + ms + " ms".
235 */
236 export function timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;
237
238 /**
239 * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.
240 */
241 export function delay<T>(promise: Promise<T>, ms: number): Promise<T>;
242 /**
243 * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.
244 */
245 export function delay<T>(value: T, ms: number): Promise<T>;
246 /**
247 * Returns a promise that will be fulfilled with undefined after at least ms milliseconds have passed.
248 */
249 export function delay(ms: number): Promise <void>;
250 /**
251 * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.
252 */
253 export function isFulfilled(promise: Promise<any>): boolean;
254 /**
255 * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.
256 */
257 export function isRejected(promise: Promise<any>): boolean;
258 /**
259 * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
260 */
261 export function isPending(promise: Promise<any>): boolean;
262
263 /**
264 * Returns a "deferred" object with a:
265 * promise property
266 * resolve(value) method
267 * reject(reason) method
268 * notify(value) method
269 * makeNodeResolver() method
270 */
271 export function defer<T>(): Deferred<T>;
272
273 /**
274 * Returns a promise that is rejected with reason.
275 */
276 export function reject<T>(reason?: any): Promise<T>;
277
278 export function Promise<T>(resolver: (resolve: (val: T | IPromise<T>) => void , reject: (reason: any) => void , notify: (progress: any) => void ) => void ): Promise<T>;
279
280 /**
281 * Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their fulfillment values before calling the original func. The returned version also always returns a promise: if func does a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively.
282 *
283 * This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that the function always returns a promise even in the face of unintentional thrown exceptions.
284 */
285 export function promised<T>(callback: (...args: any[]) => T): (...args: any[]) => Promise<T>;
286
287 /**
288 * Returns whether the given value is a Q promise.
289 */
290 export function isPromise(object: any): boolean;
291 /**
292 * Returns whether the given value is a promise (i.e. it's an object with a then function).
293 */
294 export function isPromiseAlike(object: any): boolean;
295 /**
296 * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
297 */
298 export function isPending(object: any): boolean;
299
300 /**
301 * This is an experimental tool for converting a generator function into a deferred function. This has the potential of reducing nested callbacks in engines that support yield.
302 */
303 export function async<T>(generatorFunction: any): (...args: any[]) => Promise<T>;
304 export function nextTick(callback: Function): void;
305
306 /**
307 * A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the event loop, usually as a result of done. Can be useful for getting the full stack trace of an error in browsers, which is not usually possible with window.onerror.
308 */
309 export var onerror: (reason: any) => void;
310 /**
311 * A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack property is inspected in a rejection callback, a long stack trace is produced.
312 */
313 export var longStackSupport: boolean;
314
315 /**
316 * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does).
317 * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason.
318 * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value.
319 * Calling resolve with a non-promise value causes promise to be fulfilled with that value.
320 */
321 export function resolve<T>(object: IPromise<T>): Promise<T>;
322 /**
323 * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does).
324 * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason.
325 * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value.
326 * Calling resolve with a non-promise value causes promise to be fulfilled with that value.
327 */
328 export function resolve<T>(object: T): Promise<T>;
329
330 /**
331 * Resets the global "Q" variable to the value it has before Q was loaded.
332 * This will either be undefined if there was no version or the version of Q which was already loaded before.
333 * @returns { The last version of Q. }
334 */
335 export function noConflict(): typeof Q;
336}
337
338declare module "q" {
339 export = Q;
340}
341