bluebird

How do I use Bluebird with Angular?

对着背影说爱祢 提交于 2019-12-17 04:17:41
问题 I tried using Angular with Bluebird promises: HTML: <body ng-app="HelloApp"> <div ng-controller="HomeController">{{name}} {{also}}</div> </body> JS: // javascript var app = angular.module('HelloApp', []); app.controller("HomeController", function ($scope) { var p = Promise.delay(1000).then(function () { $scope.name = "Bluebird!"; console.log("Here!", $scope.name); }).then(function () { $scope.also = "Promises"; }); $scope.name = "$q"; $scope.also = "promises"; }); window.app = app; [Fiddle]

Microsoft bing maps api and loading modules issue

我们两清 提交于 2019-12-14 04:00:49
问题 I'm building a store locator and loading a custom module via require. The custom module is dependent on Directions & Search module from microsoft. I hate the callback hell and want to pre load the modules return a promise and action on the custom module once everything is loaded. Using bluebird for Promise spec and I've tried several approaches Promise.method , Promise.promisify , new Promise(function(resolve, reject){Microsoft.Maps.loadModule({callback:resolve})}) I can't seem to get any of

TypeScript use dynamic import in ES5 with Bluebird

℡╲_俬逩灬. 提交于 2019-12-14 03:59:17
问题 I'm trying to use the new dynamic import() function in TypeScript, but I get the following error: TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option. I could include the ES2015.promise lib in my tsconfig like the message suggests, but that would make me lose type safety as I'm using Bluebird promises. I know it is possible to use Bluebird for async/await in

Promise.map not finishing because subsequent Promise.join finishes first? Promise.all?

时间秒杀一切 提交于 2019-12-14 03:20:01
问题 Am still getting the hang of promises.. Here are the models of the db collections involved: var itemSchema = new Schema({ label : String, tag : { "type": Schema.ObjectId, "ref": "tag" } }); var tagSchema = new Schema({ label : String, }); And here's the series of Promises (map, map, map, join): Right now, the Promise.join saves&completes before the 'items' map finishes running, and so the 'senders' map doesn't include the 'itemsArray' javascriptObject on save .. how can this be resolved? var

How to break out of a serial loop when using promises?

雨燕双飞 提交于 2019-12-13 18:40:05
问题 I've got a long text file that I loop through line by line to extract some event data and store it in a database. The file periodically gets updated with new data at the top. When that happens, I run through the file again extracting the new events, but I want to stop when I get to an event that's already in the database (the file is always ordered newest to oldest). Using the reduce() approach described in this answer to the question Correct way to write loops for promise, I've come up with

Call to modules in specific order in node

*爱你&永不变心* 提交于 2019-12-13 08:32:00
问题 I've used the following code to call two modules, but the invoke action is called before the validate file (I saw in debug). What I should do to verify that validateFile is called before appHandler.invokeAction ? Should I use a promise? var validator = require('../uti/valid').validateFile(); var appHandler = require('../contr/Handler'); appHandler.invokeAction(req, res); Update this is the validate file code var called = false; var glob = require('glob'), fs = require('fs'); module.exports =

Returning a promised wrapped express route to app.use()

空扰寡人 提交于 2019-12-13 07:58:57
问题 I'm looking to make an express route more modular. I was interested in using a promise to read a file then return the route. Here's the code: var express = require('express') var router = express.Router() var app = express() var Promise = require("bluebird") var fs = Promise.promisifyAll(require("fs")) function promiseRoute(file){ return fs.readFileAsync(file, "utf8") .then(JSON.parse) .then(function(file){ if(!file.url) throw new Error("missing url") router.get(file.url, function(req, res,

Possibly unhandled Error when returning promise inside a promise

送分小仙女□ 提交于 2019-12-13 07:34:28
问题 I have the following code: SuccessfulPromise().then(function() { return rejectedPromise(); }).catch(function(err) { console.log(err); }); Is it intentional that i get the above error message or is it an error? The error gets handled in the catch block and although this i get the error message Possibly unhandled Error . 回答1: You said: The problem was with sinon.stub().returns(Promise.rejected('error')) . The promise got executed before assigned to an error handler. I'd like to point out that

How to dispose resources in rejected promises with bluebird?

删除回忆录丶 提交于 2019-12-13 06:00:45
问题 How can I dispose the serial when the promise is rejected? The dispose function prints error for rejected promises. Unhandled rejection TypeError: Cannot call method 'isOpen' of undefined var pingPort = function(port){ return new promise(function(resolve, reject){ var serial = new com.SerialPort(port.comName, { baudrate: 19200, parser: com.parsers.readline(lineEnd) }, false); serial.on("data", function(data){ if (data === responseUuid){ resolve(serial); } }); serial.open(function(err){ if

Can't apply lodash partial to function created with bluebird promisifyAll

孤人 提交于 2019-12-13 04:42:17
问题 The below code takes a all the methods in object lib and promisify's them. Then I can use the callback style function as a promise, which works. Then I use _.partial provide the function and arguments, this returns a function. When I call that function it throws an error instead of wrapping the function. I have a whole bunch of tests here that show that this behavior only happens to functions generated with promisifyAll . What's the problem here and how can it be fixed? var Promise = require(