Use Promise for Commands#95
Use Promise for Commands#95gchoqueux merged 2 commits intoiTowns:masterfrom peppsac:command_with_promise
Conversation
Commands are async, so Promise are a good fit for this usage.
It will ease the transition to remove logic code from Providers.
Simplified example:
// calling site
interCommand.request(args, node);
// provider
Provider.prototype.executeCommand = function(command){
return this.getColorTextures(tile, services).then(function(result)
{
this.setTexturesLayer(result, destination);
}.bind(tile));
Would become:
// calling site
interCommand.request(args, node).then(function(textures) {
node.setTexturesLayer(result,destination);
});
// provider
Provider.prototype.executeCommand = function(command){
return this.getColorTextures(tile, services).then(function(result)
{
command.resolve(result);
};
|
I added a 2nd commit that modifies WMTS_Provider and TileProvider to take advantages of these Promise. |
|
Cool but if you can add web workers in this module to parallelize tasks, it is even better! |
For now this PR is focused on getting the groundwork done so we can improve the code later -and yes Web Workers would be nice to have :-) |
|
Be careful, promise is ES6 and doesn't seem to be supported by IE11 (see : http://caniuse.com/#feat=promises). |
|
@gcebelieu This is using BTW, https://github.com/stefanpenner/es6-promise is better maintained and seems to be the go-to polyfill. |
|
See #97 |
|
thanks, this sounds good to me :) |
Commands are async, so Promise are a good fit for this usage.
It will ease the transition to remove logic code from Providers.
Simplified example:
Would become: