'on_{error|timeout|cancel|re_apply}' triggering
425883
def trigger(on, workitem)

      tree = tree()
      err = h.applied_workitem['fields']['__error__']

      handler = on == 'on_error' ? local_on_error(err) : h[on]

      if on == 'on_error' && handler.to_s.match(/^!(.+)$/)
        handler = $1
      end

      if handler.is_a?(Hash) # on_re_apply

        wi = handler['workitem']
        fi = handler['fields']
        me = handler['merge_in_fields']

        workitem =
          if wi == 'applied' || me
            h.applied_workitem
          elsif wi
            wi
          else
            workitem
          end

        workitem['fields'] = fi if fi
        workitem['fields'].merge!(me) if me
      end

      if h.trigger && t = workitem['fields']["__#{h.trigger}__"]
        #
        # the "second take"...

        handler = t
        tree = h.supplanted['original_tree']
        workitem = h.supplanted['applied_workitem']
      end

      if
        on == 'on_error' &&
        handler.respond_to?(:match) &&
        handler.match(/([,\*]|\d+[wdhmsMy]? *:)/)
      then
        return schedule_retries(handler, err)
      end

      new_tree =
        case handler
          when Hash then handler['tree']
          when Array then handler
          when HandlerEntry then [ handler.action, {}, [] ]
          else [ handler.to_s, {}, [] ]
        end

      handler = handler.action if handler.is_a?(HandlerEntry)
      handler = handler.strip if handler.respond_to?(:strip)

      if handler =~ /^can(cel|do)$/ && (on == 'on_cancel' || h.on_cancel == nil)
        handler = handler == 'cancel' ? 'undo' : 'redo'
      end

      h.on_reply = nil if on == 'on_reply'
        # preventing cascades

      case handler

        when 'redo', 'retry'
          #
          # retry with the same tree as before

          new_tree = tree

        when 'undo', 'pass', ''
          #
          # let's forget it

          h.state = on == 'on_cancel' ? 'cancelled' : 'failed'

          reply_to_parent(workitem); return

        when 'cancel'
          #
          # let's trigger on the on_cancel

          trigger('on_cancel', workitem); return

        when 'cando'
          #
          # trigger on_cancel, then redo

          h.on_reply = tree

          trigger('on_cancel', workitem); return

        when 'raise'
          #
          # re-raise

          raise Ruote.constantize(err['class']), err['message'], err['trace']

        when /^(?:store|bury) *: *(.+)/

          h.state = 'failed'
          set_vf($1, err, :workitem => workitem)

          reply_to_parent(workitem); return

        when CommandExpression::REGEXP
          #
          # a command like 'jump to shark'...

          hh = handler.split(' ')
          command = hh.first
          step = hh.last

          h.state = nil
          workitem['fields'][CommandMixin::F_COMMAND] = [ command, step ]

          reply(workitem); return

        #else
        #
        #  if h.trigger
        #    #
        #    # do not accept participant or subprocess names
        #    # for "second trigger"
        #
        #    h.state = 'failed'
        #    reply_to_parent(workitem)
        #    return
        #  end
          #
          # actually, let's not care about that, let's trust people.
      end

      workitem = h.applied_workitem if on == 'on_error'

      #
      # supplant this expression with new tree

      r = try_unpersist

      raise(
        "failed to remove exp to supplant " +
        "#{Ruote.to_storage_id(h.fei)} #{tree.first}"
      ) if r.respond_to?(:keys)

      if new_tree[0].match(/^!(.+)$/); new_tree[0] = $1; end
      new_tree[1]['_triggered'] = on

      attributes.each { |k, v|
        new_tree[1][k] = v if (k.match(/^on_/) && k != on) || k == 'tag'
      }
        #
        # let the triggered tree have the same on_ attributes as the original
        # expression, so that on_cancel/on_error/on_x effects still apply
        #
        # 'tag' is copied as well. (so that 'left_tag' is emitted too)
        #
        # Should 'timeout', should other common attributes be copied as well?

      @context.storage.put_msg(
        'apply',
        { 'fei' => h.fei,
          'parent_id' => h.parent_id,
          'tree' => new_tree,
          'workitem' => workitem,
          'variables' => h.variables,
          'trigger' => on,
          'on_reply' => h.on_reply,
          'supplanted' => {
            'tree' => tree,
            'original_tree' => original_tree,
            'applied_workitem' => h.applied_workitem,
            'variables' => h.variables
          }})
    end
356052
function cancel() {
    timeouts.forEach(function (timeout) {
      clearTimeout(timeout);
    });
    Object.keys(callbacks).forEach(function (key) {
      callbacks[key]('cancel');
      delete callbacks[key];
    });
    timeouts = [];
  }
782006
def _on_timeout(self, info: str = None) -> None:
        
        self._timeout = None
        error_message = "Timeout {0}".format(info) if info else "Timeout"
        if self.final_callback is not None:
            self._handle_exception(
                HTTPTimeoutError, HTTPTimeoutError(error_message), None
            )
239948
def on_event(event_type, target, extra = nil)
      case event_type
      when :error
        say_status :error, target, :red
        shell.say extra, :red if options['verbose'] || options['bail']

        raise 'Build error' if options['bail']
      when :deleted
        say_status :remove, target, :green
      when :created
        say_status :create, target, :green
      when :identical
        say_status :identical, target, :blue
      when :skipped
        say_status :skipped, target, :blue
      when :updated
        say_status :updated, target, :yellow
      else
        say_status event_type, extra, :blue
      end
    end
235759
function (events) {
        "use strict";
    
        requirejs.onError = function (err) {
    
            if (err.requireType === 'timeout') {
    
                events.trigger('error');
                for (var i in err.requireModules) {
                    requirejs.undef(err.requireModules[i]);
                }
    
                // try again loading modules
                require(err.requireModules, function () {
                    events.trigger('retried');
                });
    
            }
            else {
                console.log(err.stack);
            }
    
        };
    
    }
884771
function(client, window, timeoutSeconds, action, args) {
      this._window = window;
      if (!timeoutSeconds)
        timeoutSeconds = 30;

      var doTimeout = function (action, client, args) {
        return function () {
          return action.apply(client, args);
        };
      };
      this.timeout = setTimeout(doTimeout(action, client, args), timeoutSeconds * 1000);

      this.cancel = function() {
        this._window.clearTimeout(this.timeout);
      };
    }
1091752
function TimeoutError(message) {
  this.message = message;
  this.timeout = true;

  Error.captureStackTrace(this, arguments.callee);
}
733714
function triggerAndReturn(context, eventName, data) {
    var event = $.Event(eventName)
    $(context).trigger(event, data)
    return !event.defaultPrevented
  }
1207235
def try_trigger(event_name)
      if valid_state?(event_name)
        yield
      else
        exception = InvalidStateError
        catch_error(exception) ||
          fail(exception, "inappropriate current state '#{current}'")

        false
      end
    end
812093
def on_timeout(limit, handler=handler_func, hint=None):
    
    def notify_handler(signum, frame):
        handler("'%s' is not finished in %d second(s)." % (hint, limit))

    def __decorator(function):
        def __wrapper(*args, **kwargs):
            import signal
            signal.signal(signal.SIGALRM, notify_handler)
            signal.alarm(limit)
            result = function(*args, **kwargs)
            signal.alarm(0)
            return result
        return wraps(function)(__wrapper)
    return __decorator
120094
function onConnectionError(err) {
        var codeName = errors.classify(err);

        var loggerInfo = conn.extendLogInfo({
            error: err
        });

        if (codeName === 'Timeout' ||
            codeName === 'NetworkError') {
            self.logger.warn('Got a connection error', loggerInfo);
        } else {
            self.logger.error('Got an unexpected connection error', loggerInfo);
        }
        delete self.serverConnections[socketRemoteAddr];
    }
714463
function on_error(xhr, status, error) {
	var response = new anchor._response_handler(null);
	response.okay(false);
	response.message(error);
	response.message_type(status);
	anchor.apply_callbacks('error', [response, anchor]);
    }
878769
def on(event, &proc)
      unless @events.has_key? event
        raise Error, "`#{event}` is not a valid event type"
      end
      event_id = new_event_key
      @events[event][event_id] = proc
      EventDescriptor.new(event, event_id)
    end
1215059
function handler ( err, data ){
      if ( callback != null ){
        callback.apply( b9, arguments );
      }
      // only emit events when there is no error
      if ( err == null ){
        b9.emit.call( b9, method, data );
      }
    }
769968
def on_api_error(self, error_status=None, message=None, event_origin=None):

        
        if message.meta["error"].find("Widget instance not found on server") > -1:
            # widget is missing on the other side, try to re-attach
            # then try again
            error_status["retry"] = True
            self.comm.attach_remote(
                self.id,
                self.remote_name,
                remote_name=self.name,
                **self.init_kwargs
            )
798250
def _onMethodTimeout(self, serial, d):
        
        del self._pendingCalls[serial]
        d.errback(error.TimeOut('Method call timed out'))
184643
def trigger_failure(data=nil)
      event.success = false
      event.data = data
      event.trigger
    end