problem about q-Collection of common programming errors


  • Oliver Kane
    knockout.js breeze durandal q
    Durandal.JS and Breeze.JS have some troubles playing together. Durandal is based on a few libraries, the two of note are Require and Knockout. My original project, prior to using the modular pattern introduced by Require, used the Knockout style bindings on the Breeze models.On my journey, I found out that Breeze can work with multiple libraries for Breeze’s models, such as Backbone, Knockout, Angular, and other frameworks. When Breeze is loaded as a Require module, Breeze checks to see if th

  • Benjamin Gruenbaum
    javascript callback promise q bluebird
    I want to work with promises but I have a callback API in a format like:1. DOM load or other one time event:window.onload; // set to callback … window.onload = function(){};2. Plain callback:function request(onChangeHandler){ … request(function(){// change happened });3. Node style callback (“nodeback”):function getStuff(dat,callback){ … getStuff(“dataParam”,function(err,data){}4. A whole library with node style callbacks:API; API.one(function(err,data){API.two(function(err,data2){API.thre

  • tengen
    angularjs internet-explorer-9 q
    In Angular 1.2.0, there is this funny comment:// IE stupidity! (IE doesn’t have apply for some native functions)It sits on line 9835 in the functionCall function:functionCall: function(fn, contextGetter) {var argsFn = [];if (this.peekToken().text !== ‘)’) {do {argsFn.push(this.expression());} while (this.expect(‘,’));}this.consume(‘)’);var parser = this;return function(scope, locals) {var args = [];var context = contextGetter ? contextGetter(scope, locals) : scope;for (var i = 0; i < argsFn.l

  • Grummle
    node.js loops promise q
    What would be the idiomatic way to do something like a while loop with promises. So:do something if the condition still stands do it again repeat then do something else.dosomething.then(possilblydomoresomethings).then(finish)I’ve done it this way I was wondering if there were any better/more idomatic ways?var q = require(‘q’);var index = 1;var useless = function(){var currentIndex = index;console.log(currentIndex)var deferred = q.defer();setTimeout(function(){if(currentIndex > 10)deferred.re

  • dc7a9163d9
    asp.net asp.net-mvc breeze hottowel q
    I created an Asp.Net MVC and used nuget to add HotTowel (VS2013 which is not available anymore) and updated breeze to V1.4.5. I ran the app and got the following error in the output window. Are these bugs of Q.js and breeze?Exception was thrown at line 68, column 5 in http://localhost:49890/scripts/Q.js 0x80004005 – JavaScript runtime error: unknown exception Exception was thrown at line 433, column 9 in http://localhost:49890/scripts/Q.js 0x80004005 – JavaScript runtime error: unknown exception

  • Jeremie Parker
    promise sails.js q
    I’m starting to convert my callback code to promises in Sails.js, but I don’t understand how I can raise custom errors and handle them in the promise chain. Sails.js uses Q as its promise library.User.findOne({email: req.param(‘professorEmail’), role: ‘professor’}).then(function (user) {if (user) {return Course.create({user_id: user.id,section: req.param(‘section’),session: req.param(‘session’),course_code: req.param(‘course_code’)});} else {// At this point `user` is undefined which means that

  • The_Smallest
    breeze q
    When query execution fails (for example database constraint violation on saving) i can see in console.Should be empty: []Here is the example (you can see Should be empty: [] in console)): breeze.EntityQuery.from(“EntityThatDoesnotExist”).using(new breeze.EntityManager(“http://todo.breezejs.com/api/todos”)).execute().then(function () { }).fail(function () { });http://jsfiddle.net/vMhkg/3/I’m new to Breeze and Q, so my question is: should I just just ignore this? Or am I doing something wrong? Or

  • Eric Hotinger
    javascript angularjs requirejs breeze q
    I am creating a single page app built on AngularJS, Breeze, and RequireJS. In setting up AMD with requirejs to work with Angular and Breeze, I encountered an issue with Breeze’s dependency on “q”. If the configuration rule for “q” is lowercase, even if there is no explicit export in the “shim”, Breeze gives this error:Uncaught Error: Unable to initialize Q. See https://github.com/kriskowal/q “http://localhost:1498/Scripts/shared/breeze.js”breeze.js:1`When require config changes all references fr

  • Conradub
    javascript asynchronous web-api deferred q
    Already had a layer in JS which helps Gets and Posts to the server with the following implementations :var getJson = function(url, callback, onError) {$.get(url).done(function(data) {if(callback != null)callback(data);}).fail (function(error) {if(onError != null)onError (error);elsemy.notification.notifyError(onErrorMessage);}); };var postJSON = function(url, data, callback, onError) {$.ajax({url : url ,type: “POST” ,contentType : “application/json”dataType : “json” ,date : ko.toJSON(data)}).don

  • bob_cobb
    javascript node.js callback promise q
    I’m doing a bunch of deferred/promises with the Q library which works fine, but once I get back some of my data in one of the chained callbacks, I want to manipulate it in some way.E.g.var getFavorites = function(submissionId) {deferred = Q.defer();Submission.getFavorites({submissionId : submissionId}, function(err, favorites) {if (err) {deferred.reject(err);} else {deferred.resolve(favorites);}});return deferred.promise; };var didUserFavorite = function(favorites) {var didUserLike;deferred = Q.

  • gremo
    node.js asynchronous promise q
    Even if well documented q framework is quite hard to understand if you are programming with Node.js for a few days. But I like to learn about it!var Q = require(‘q’); var fs = require(‘fs’);// Make the promise manually (returns a value or throws an error) var read1 = fs.readFile(fname, enc, function (err, data) {if(err) throw err;return data; });// Convenient helper for node, equivalent to read1? var read2 = Q.nfbind(fs.readFile);// Uh?! var read3 = function (fname, enc) {var deferred = Q.defer

  • hippietrail
    javascript asynchronous mongoose promise q
    I’m using mongoose to insert some data into mongodb. The code looks like:var mongoose = require(‘mongoose’); mongoose.connect(‘mongo://localhost/test’); var conn = mongoose.connection;// insert users conn.collection(‘users’).insert([{/*user1*/},{/*user2*/}], function(err, docs) {var user1 = docs[0], user2 = docs[1];// insert channelsconn.collection(‘channels’).insert([{userId:user1._id},{userId:user2._id}], function(err, docs) {var channel1 = docs[0], channel2 = docs[1];// insert articlesconn.co

  • Vprnl
    javascript node.js promise deferred q
    I think this is a really stupid question but I’m having a hard time wrapping my head around promises. I’m using Q (for nodejs) to sync up a couple of async functions. This works like a charm. var first = function () {var d = Q.defer();fs.readdir(path,function(err,files){if(err) console.log(err);d.resolve(files);});return d.promise;};var second = function (files) {var list = new Array;files.forEach(function(value, index){var d = Q.defer();console.log(‘looking for item in db’, value);db.query(‘SE

  • hippietrail
    javascript node.js loops q
    The popular JavaScript module Q implements the deferred / promise / futures concept. I think it’s mainly used with node.js but it support browser use as well. I’m using it with node.js.To do sequential calls you chain one promise to the next using then() but in a loop it can so counterintuitive than I’m finding it difficult to do the same as this pseudocode:forever {l = getline();if (l === undefined) {break;} else {doStuff(l);} }The Q documentation includes an example which seems pretty similar:

  • Max Bates
    angularjs local-storage promise q
    I’ve written a service Collector to store my models, which interfaces with localStorage and my server. I have a function Collector.retrieveModel(uuid) which retrieves a model from the collector, first checking localStorage to see if it is already extant, otherwise requesting it from my server. Here’s what it looks like:var retrieveModel = function(uuid) {var deferred = $q.defer();var promise = deferred.promise;if (typeof uuid === ‘undefined’) {console.log(“retrieveModel called without param”);de

  • bob_cobb
    javascript node.js asynchronous q
    In “view” method within my controller was previously using node-async but I wanted to try out using q.I’m currently trying to convert thisexports.view = function (req, res) {var category = req.params.category,id = req.params.id,ip = req.connection.remoteAddress,slug = req.params.slug,submission,userId = typeof req.session.user !== ‘undefined’ && req.session.user.id ? req.session.user.id : null,views; var getSubmission = function (submissionId, callback) {Submission.getSubmission({id: sub

  • Hawk
    angularjs breeze q
    I’m having problems executing a breeze query with angular resolve before the view is rendered. I’m trying to get some data from the server before the view is rendered with breeze. I’m using $routeProvider.when(‘/countries’, { templateUrl: ‘App/partials/countries.html’, controller: Ctrl, resolve: Ctrl.resolve }).controller and service snippets:function Ctrl($scope, Q, datacontext, countries) {//…}function getCountries(forceRefresh) {var query = entityQuery.from(“countries”).orderBy(“name”);retu

  • PatchCR
    jquery angularjs promise deferred q
    I am developing both a javascript library and an AngularJS front-end. The JavaScript Library needs to be portable so it cannot rely on AngularJS. We use a pretty standard servlet query pattern:queryService = function(url, method, params, resultHandler, queryId) {var request = {jsonrpc: “2.0”,id: queryId || “no_id”,method: method,params: params};$.post(url, JSON.stringify(request), handleResponse, “json”);function handleResponse(response){if (response.error)console.log(JSON.stringify(response, nu

  • Smokefoot
    node.js promise q
    I have a function in a chain of promises that may or may not do something. E.g.getYear().then(function(results){if(results.is1999) return party();else return Q.fcall(function(){/*do nothing here*/});}).then(sleep)Where getYear, party, and sleep all return promises. Is there a more concise way to write the else statement? That is do nothing but still return a chainable promise?

  • BoxerBucks
    angularjs q
    I am trying to chain together multiple deferred function calls such that the next call gets the results of the previous deferred.resolve. When I chain together more than 2 of these calls, the data stops being returned.Here is the basic code inside an angular controller:$scope.runAsync = function() {var asyncFn1 = function(data){var deferred = $q.defer();$timeout(function(){console.log(“Async fn1 ” + data);$scope.outputLines.push(“Async fn1 ” + data);deferred.resolve(“Async fn1 ” + data);},1000);

  • Kaizo
    javascript scope q
    How does the scope of the Q promises work? As far as I know the callback of the “then” is called by window, like a setTimeout.In this example (just an example to understand how it works):var getFileText = function() {var deferred = Q.defer();Server.readFile(“foo.txt”, “utf-8”, function (error, text) {if (error) {deferred.reject(new Error(error));} else {deferred.resolve(text);}});return deferred.promise; };var Foo = function () {getFileText().then(this.showFile); };Foo.prototype.showFile = func

  • hippietrail
    javascript asynchronous callback promise q
    I some problems understanding how to use “q” (https://github.com/kriskowal/q) a promises library for javascript:var delayOne = function() {setTimeout(function() {return ‘hi’;}, 100); };var delayTwo = function(preValue) {setTimeout(function() {return preValue + ‘ my name’;}, 200); };var delayThree = function(preValue) {setTimeout(function() {return preValue + ‘ is bodo’;}, 300); };var delayFour = function(preValue) {setTimeout(function() {console.log(preValue);}, 400);};Q.fcall(delayOne).then(del

  • StrandedPirate
    knockout.js breeze durandal q
    I’m getting the following error from breeze and q.js when my view and model are being bound by a compose binding statement using durandal. I wrote the view in question in isolation and it works great until I try to do a compose binding with it, it throws this error. I tried moving all the custom properties from my entity constructor function to the initializer and also defering evalution of my computed’s but that did nothing to thwart the error. I’m not sure which framework is causing this probl

Web site is in building