Calls the callable only when the rule is triggered.
334622
def handle_data(self, context, data, dt):
        
        if self.rule.should_trigger(dt):
            self.callback(context, data)
582563
public void called(Matcher<Integer> numberOfCalls) {
        Rule rule = ruleBuilder.toRule();
        int matchingCalls = (int)requests.stream()
                .filter(req -> rule.matches(req))
                .count();

        if (!numberOfCalls.matches(matchingCalls)) {
            throw new IllegalStateException(String.format("Expected %s calls, but found %s.", numberOfCalls, matchingCalls));
        }
    }
15697
def on_change(self, callable_):
        
        self.model.add_observer(
            callable_, self.entity_type, 'change', self.entity_id)
763452
def on_remove(self, callable_):
        
        self.model.add_observer(
            callable_, self.entity_type, 'remove', self.entity_id)
961532
def _call_watcher(self_, watcher, event):
        
        if self_.self_or_cls.param._TRIGGER:
            pass
        elif watcher.onlychanged and (not self_._changed(event)):
            return

        if self_.self_or_cls.param._BATCH_WATCH:
            self_._events.append(event)
            if watcher not in self_._watchers:
                self_._watchers.append(watcher)
        elif watcher.mode == 'args':
            with batch_watch(self_.self_or_cls, run=False):
                watcher.fn(self_._update_event_type(watcher, event, self_.self_or_cls.param._TRIGGER))
        else:
            with batch_watch(self_.self_or_cls, run=False):
                event = self_._update_event_type(watcher, event, self_.self_or_cls.param._TRIGGER)
                watcher.fn(**{event.name: event.new})
1125204
private static <T> Callable<T> threadRenaming(final String name, final Callable<T> callable) {
    checkNotNull(name);
    checkNotNull(callable);
    return new Callable<T>() {
      @Override public T call() throws Exception {
        Thread currentThread = Thread.currentThread();
        String oldName = currentThread.getName();
        currentThread.setName(name);
        try {
          return callable.call();
        } finally {
          currentThread.setName(oldName);
        }
      }
    };
  }
124281
public void setActivate(RuleProxyField ruleProxyField,
            RuleContext ruleContext)
    {
        if (ruleProxyField.isInActive()) // only do it if the field changes
        {
            m_activateFields.add(ruleProxyField.getProxyField());
            ruleContext.addActivate(ruleProxyField);
        }
    }
739457
def _on_click(self, *args):
        
        if callable(self._callback):
            self._callback(self.selection)
372199
def add_rule(self, name, callable_):
        """"""
        assert isinstance(name, basestring)
        assert callable(callable_)
        self.project_rules_.add_rule(name, callable_)
304322
def _check_cb(cb_):
    '''
    
    '''
    if cb_ is not None:
        if hasattr(cb_, '__call__'):
            return cb_
        else:
            log.error('log_callback is not callable, ignoring')
    return lambda x: x
792796
def on_done(self):
        
        if self._d:
            self._d.callback(self)
            self._d = None
396982
def call_only_once(func):
    '''
    
    '''

    def new_func(*args, **kwargs):
        if not new_func._called:
            new_func._called = True
            return func(*args, **kwargs)

    new_func._called = False
    return new_func
807566
private function checkCallback() : void
    {
        if (isset($this->onload) && !$this->is_loaded) {
            $this->is_loaded = true;
            call_user_func($this->onload, $this);
        }
    }
820706
private <T> T call(UfsCallable<T> callable) throws IOException {
    LOG.debug("Enter: {}", callable);
    String methodName = callable.toString().split(NAME_SEPARATOR)[0];
    try (Timer.Context ctx = MetricsSystem.timer(getQualifiedMetricName(methodName)).time()) {
      T ret = callable.call();
      LOG.debug("Exit (OK): {}", callable);
      return ret;
    } catch (IOException e) {
      MetricsSystem.counter(getQualifiedFailureMetricName(methodName)).inc();
      LOG.debug("Exit (Error): {}, Error={}", callable, e.getMessage());
      throw e;
    }
  }
494666
def calledWithExactly(cls, spy, *args, **kwargs): #pylint: disable=invalid-name
        
        cls.__is_spy(spy)
        if not (spy.calledWithExactly(*args, **kwargs)):
            raise cls.failException(cls.message)
76555
def with_validator(self, validator):
    """"""
    if not callable(validator):
      raise ValueError('Validator must be callable', validator)
    self.validators.append(validator)
    self._cached = None
    return self
637604
@InternalFunction(precedence=1,isAssign=true)
    public void activate(RuleContext ruleContext,RuleProxyField ruleProxyField)
    {
        setActivate(ruleProxyField,ruleContext);
    }