Skip to content

@derickbailey /1.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
promises
// ajax call with async callback
// -----------------------------
$.ajax({
type: "GET",
url: "/foo",
success: function(data){
// this is a callback, used for the async result
}
});
// DOM event handler with a callback
// ---------------------------------
$("#some-element").click(function(e){
// this is a callback for the element click
});
function doSomeStuff(callback){
// do some processing here
var foo = getBar();
// call the callback, passing in a variable
callback(foo);
// do some more processing here if needed
}
doSomething(function(foo){
foo = processFoo(foo);
doMoreStuff(foo, function(bar){
var baz = getBaz(foo);
stillMore(baz, function(quux){
gettingPrettyBad(function(widget){
return widget + baz;
});
});
});
});
function doSomething(){
var promise = new Promise();
// ... do async stuff here
asyncFoo(function(){
// resolve the promise
promise.complete();
});
return promise;
}
var promise = doSomething();
promise.then(function(foo){
// continue working here
});
args.setPromise(WinJS.UI.processAll().then(function () {
// ...
}
return new WinJS.Promise(function (complete, error, progress) {
applicationData.current.localFolder.createFolderAsync(thumbnailFolderName, creationCollisionOption.replaceExisting)
.then(function (folder) {
var localThumbnail = 'ms-appdata:///local/' + thumbnailFolderName + '/';
var promises = files.map(function (fileInfo) {
var createFile = folder.createFileAsync(fileInfo.name, creationCollisionOption.replaceExisting);
return createFile.then(function (newFile) {
return newFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (output) {
var input = fileInfo.thumbnail.getInputStreamAt(0);
return randomAccessStream.copyAsync(input, output).then(function () {
return output.flushAsync().then(function () {
input.close();
output.close();
return fileInfo.name;
});
});
});
});
});
WinJS.Promise.join(promises).then(function (files) {
var paths = files.map(function (file) {
return localThumbnail + file;
});
complete(paths);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.