1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mirrors-dojo

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
when.js 1.9 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Kenneth G. Franqueiro Отправлено 17.02.2013 22:46 2ba455c
define([
"./Deferred",
"./promise/Promise"
], function(Deferred, Promise){
"use strict";
// module:
// dojo/when
return function when(valueOrPromise, callback, errback, progback){
// summary:
// Transparently applies callbacks to values and/or promises.
// description:
// Accepts promises but also transparently handles non-promises. If no
// callbacks are provided returns a promise, regardless of the initial
// value. Foreign promises are converted.
//
// If callbacks are provided and the initial value is not a promise,
// the callback is executed immediately with no error handling. Returns
// a promise if the initial value is a promise, or the result of the
// callback otherwise.
// valueOrPromise:
// Either a regular value or an object with a `then()` method that
// follows the Promises/A specification.
// callback: Function?
// Callback to be invoked when the promise is resolved, or a non-promise
// is received.
// errback: Function?
// Callback to be invoked when the promise is rejected.
// progback: Function?
// Callback to be invoked when the promise emits a progress update.
// returns: dojo/promise/Promise
// Promise, or if a callback is provided, the result of the callback.
var receivedPromise = valueOrPromise && typeof valueOrPromise.then === "function";
var nativePromise = receivedPromise && valueOrPromise instanceof Promise;
if(!receivedPromise){
if(arguments.length > 1){
return callback ? callback(valueOrPromise) : valueOrPromise;
}else{
return new Deferred().resolve(valueOrPromise);
}
}else if(!nativePromise){
var deferred = new Deferred(valueOrPromise.cancel);
valueOrPromise.then(deferred.resolve, deferred.reject, deferred.progress);
valueOrPromise = deferred.promise;
}
if(callback || errback || progback){
return valueOrPromise.then(callback, errback, progback);
}
return valueOrPromise;
};
});

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mirrors-dojo.git
git@api.gitlife.ru:oschina-mirror/mirrors-dojo.git
oschina-mirror
mirrors-dojo
mirrors-dojo
master