q

Q: Promisify Synchronous operations for chaining promises?

对着背影说爱祢 提交于 2020-01-05 07:53:08
问题 Is there any merit in promisifying synchronous operations so that by design they can be chained in onSuccess or onError callbacks? Eg: function loadSettings(path) { if (fs.existsSync(path)) { return Q(fsJson.loadSync(path)); } return new Q.defer().reject('No local settings!'); } doingSomethingFirst() .then(loadSettings, obtainSettings) .then(doSomethingWithSettings) .done() What's best? 回答1: No, moreover, it gives the false impression that these methods are async so you or other developers

How to retry an xhr request which returns a promise recursively for atleast n times on status 0

本秂侑毒 提交于 2020-01-05 05:31:06
问题 I have written the below piece of code. makeRequest gets called and I want to retry this when xhr status is 0. The problem is I am not able to resolve the correct promise, the retry logic fetches the correct response in nth attempt but fails to propagate to the caller method. How do I resolve this issue. var makeRequest = function(method, urlToBeCalled, payload) { var deferred = $q.defer(); var xhr = new XMLHttpRequest(); xhr.open(method, encodeURI(urlToBeCalled), true); setHttpRequestHeaders

Error handling in Q promise

[亡魂溺海] 提交于 2020-01-04 10:49:06
问题 I'm a bit confused understanding Q promise error handling. Let's say I have the following functions (for demonstration only): function first() { console.log('first'); var done = Q.defer(); done.resolve('first'); return done.promise; } function second() { console.log('second'); var done = Q.defer(); done.resolve('second'); return done.promise; } function third() { console.log('third'); var done = Q.defer(); done.resolve('third'); return done.promise; } function fourth() { console.log('fourth')

Durandal Modal Won't Close

前提是你 提交于 2020-01-04 06:36:26
问题 Modals are turning out to be more difficult than I thought :/ Got the modal loading up a view / view modal properly, clicking the save button saves the information (I do get a 'Should be Empty : []' from Q.js but apparently this isn't a problem?) the problem I am having is probably related to promises but if it is I can't find it. Parent's view model - var createNew = function () { app.showModal(tfcreate).then(function (modalResult) { if (!modalResult) { return false; } var templateId =

How to load Q library with Require.js?

我怕爱的太早我们不能终老 提交于 2020-01-04 05:41:13
问题 My library use kriskowal/Q promises library and now I'm trying to load (with requirejs) application that use my library so I put all paths and shims and my requirejs.config section looks like this: requirejs.config({ baseUrl: './', catchError: false, paths: { beril: '../engine/build/src/bundle', lodash: 'bower_components/lodash/lodash', three: 'bower_components/three.js/build/three', q: 'bower_components/q/q', }, shim: { lodash: { exports: '_' }, three: { exports: 'THREE' }, q: { exports: 'Q'

execute promises recursively nodejs

Deadly 提交于 2020-01-03 21:10:45
问题 the following function creates new folder on my server via xmlrpc var createFolder = function(folder_name) { var defer = Q.defer(); client.methodCall('create_folder', [sessionID, folder_name], function(err, resp) { if (err) { if (err.responseString && err.responseString.match('already exist')) { //call the same function recursively with folder_name+Math.round(Math.random()*100) } else { defer.reject(err); } } else { defer.resolve(folder_name); } }); return defer.promise; } The functions

execute promises recursively nodejs

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 21:09:33
问题 the following function creates new folder on my server via xmlrpc var createFolder = function(folder_name) { var defer = Q.defer(); client.methodCall('create_folder', [sessionID, folder_name], function(err, resp) { if (err) { if (err.responseString && err.responseString.match('already exist')) { //call the same function recursively with folder_name+Math.round(Math.random()*100) } else { defer.reject(err); } } else { defer.resolve(folder_name); } }); return defer.promise; } The functions

Angularjs custom directive using http promise not binding with template

守給你的承諾、 提交于 2020-01-03 02:25:30
问题 I am new to angularjs and want to add new feature in existing code. But code is not working as expected. I know i am not doing it the right way. Please correct me where is the mistake. I don't know why controller is not used but directive is used in this approach? Here is my custom service and custom directive directive code. Service code: angular.module("quickquiz-builder").service("SettingsService", function ($http, $q) { return { /* Return deffered promise response */ get: function() { var

BreezeJs with dedicated web worker

半世苍凉 提交于 2020-01-01 17:43:10
问题 I am trying to initialize a Breeze manager inside a 'Web Worker'. RequireJs, knockout, q, breeze are being imported inside the worker. After a call to: EntityQuery.from('name').using(manager).execute() , the following error appears: Uncaught Error: Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q . A live preview is uploaded here http://plnkr.co/edit/meXjKa?p=preview (plunk supports downloading for easier debug). EDIT -- relevant code Worker.js importScripts('knockout

BreezeJs with dedicated web worker

ⅰ亾dé卋堺 提交于 2020-01-01 17:43:06
问题 I am trying to initialize a Breeze manager inside a 'Web Worker'. RequireJs, knockout, q, breeze are being imported inside the worker. After a call to: EntityQuery.from('name').using(manager).execute() , the following error appears: Uncaught Error: Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q . A live preview is uploaded here http://plnkr.co/edit/meXjKa?p=preview (plunk supports downloading for easier debug). EDIT -- relevant code Worker.js importScripts('knockout