]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/promise/tracer.js.uncompressed.js
1 define("dojo/promise/tracer", [
5 ], function(lang
, Promise
, Evented
){
14 // Trace promise fulfillment.
16 // Trace promise fulfillment. Calling `.trace()` or `.traceError()` on a
17 // promise enables tracing. Will emit `resolved`, `rejected` or `progress`
20 on: function(type, listener){
22 // Subscribe to traces.
24 // See `dojo/Evented#on()`.
26 // `resolved`, `rejected`, or `progress`
28 // The listener is passed the traced value and any arguments
29 // that were used with the `.trace()` call.
34 var evented
= new Evented
;
35 var emit
= evented
.emit
;
37 // Emit events asynchronously since they should not change the promise state.
38 function emitAsync(args
){
39 setTimeout(function(){
40 emit
.apply(evented
, args
);
44 Promise
.prototype.trace = function(){
48 // Tracing allows you to transparently log progress,
49 // resolution and rejection of promises, without affecting the
50 // promise itself. Any arguments passed to `trace()` are
51 // emitted in trace events. See `dojo/promise/tracer` on how
53 // returns: dojo/promise/Promise
54 // The promise instance `trace()` is called on.
56 var args
= lang
._toArray(arguments
);
58 function(value
){ emitAsync(["resolved", value
].concat(args
)); },
59 function(error
){ emitAsync(["rejected", error
].concat(args
)); },
60 function(update
){ emitAsync(["progress", update
].concat(args
)); }
65 Promise
.prototype.traceRejected = function(){
67 // Trace rejection of the promise.
69 // Tracing allows you to transparently log progress,
70 // resolution and rejection of promises, without affecting the
71 // promise itself. Any arguments passed to `trace()` are
72 // emitted in trace events. See `dojo/promise/tracer` on how
74 // returns: dojo/promise/Promise
75 // The promise instance `traceRejected()` is called on.
77 var args
= lang
._toArray(arguments
);
78 this.otherwise(function(error
){
79 emitAsync(["rejected", error
].concat(args
));