code: function(_fun) {
        var status = {
          canceled: false
        }, pending = this.$pending || (this.$pending = []);
  
        pending.push(status);
  
        return this.$always(function() {
          var oldAction = this.$$action;
          try {
            if(!status.canceled) {
              this.$$action = status;
              return _fun.call(this);
            } else {
              return $q.reject(this);
            }
          } finally {
            // restore object state and pending actions
            this.$$action = oldAction;
          }
        }).$finally(function() {
          // after action and related async code finishes, remove status from pending list
          pending.splice(pending.indexOf(status), 1);
        });
      }
docs: Actions API 
  @memberof CommonApi#
  
  @description Registers a new action to be executed in the promise queue.
  
  Registered pending actions can be canceled using `$cancel`
  
  `$cancel` will also cancel any ongoing call to `$send` (will not abort it yet though...)
  
  @return {CommonApi} self