34 | function init(resolver) { |
35 | var handler = new Pending(); |
36 | |
37 | try { |
38 | resolver(promiseResolve, promiseReject, promiseNotify); |
39 | } catch (e) { |
40 | promiseReject(e); |
41 | } |
42 | |
43 | return handler; |
44 | |
45 | |
46 | * Transition from pre-resolution state to post-resolution state, notifying |
47 | * all listeners of the ultimate fulfillment or rejection |
48 | * @param {*} x resolution value |
49 | */ |
50 | function promiseResolve (x) { |
51 | handler.resolve(x); |
52 | } |
53 | |
54 | * Reject this promise with reason, which will be used verbatim |
55 | * @param {Error|*} reason rejection reason, strongly suggested |
56 | * to be an Error type |
57 | */ |
58 | function promiseReject (reason) { |
59 | handler.reject(reason); |
60 | } |
61 | |
62 | |
63 | * Issue a progress event, notifying all progress listeners |
64 | * @param {*} x progress event payload to pass to all listeners |
65 | */ |
66 | function promiseNotify (x) { |
67 | handler.notify(x); |
68 | } |
69 | } |