Two things, first of all, Promise.all
in Bluebird does not accept a second argument like that, it returns a promise, try :
Promise.all([loadSearch(), loadDirections()]).then(function(results) {
//do something
});
Or better
Promise.all([loadSearch(), loadDirections()]).spread(function(search,dirs) {
//do something
});
Second of all, the methods of defer are not bound to the defer instance (JS has dynamic this), use the promise constructor instead:
function loadDirections() {
return new Promise(function(resolve){
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
callback: resolve // since this is not a method this is not bound
});
});
}
And so on. generally, it is better to prefer the promise constructor over the deferred interface in Bluebird.
In total:
function loadSearch() {
return new Promise(function(resolve){
Microsoft.Maps.loadModule('Microsoft.Maps.Search', {
callback: resolve
});
});
}
function loadDirections() {
return new Promise(function(resolve){
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
callback: resolve
});
});
}
Promise.all([loadDirections(),loadSearch()]).spread(function(dir,search){
//both done, results here
});
For what it's worth - I've just raised the issue and better error messages will be given in future versions of Bluebird.