Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.23 KB | None | 0 0
  1. function buyPackage():Promise<String>
  2.     {
  3.         /**
  4.             var transaction = _buyPackage(model.packageId);
  5.             transaction.handle(function(v:Outcome<String, Error>) {
  6.                 // TODO: Bad way for calling strategy. Proper way is rework BuyCreditAlertFinishAdapterStrategyMacro and all mactro/comands which using in it, and after it use @Map
  7.                 var m = new CommandMapping(BuyCreditAlertFinishAdapterStrategyMacro);
  8.                 new CommandExecutor(injector, module).executeCommand(m);
  9.             });
  10.             return transaction;
  11.          */
  12.         var transaction = _buyPackage(model.packageId);
  13.        
  14.         transaction.flatMap(function(v:Outcome<String, Error>) {
  15.             switch(v){
  16.                 case Outcome.Success(result):
  17.                     return Future.async( function(trigger) {
  18.                         var m = new CommandMapping(BuyCreditAlertFinishAdapterStrategyMacro);
  19.                         m.withCompleteHandler(function(command:IAsyncCommand){
  20.                             trigger(Outcome.Success(result));
  21.                         });
  22.                         m.withFailHandler(function(command:IAsyncCommand){
  23.                             trigger(Outcome.Failure(new Error("Macro failed BuyCreditAlertFinishAdapterStrategyMacro")));
  24.                         });
  25.                         new CommandExecutor(injector, module).executeCommand(m);
  26.                     };
  27.                 case Outcome.Failure(error):
  28.                     return Future.sync(v);
  29.             }
  30.         });
  31.         return transaction;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement