Subscribe to a particular signal
 @param signal_name Symbol
 @param step Symbol May be :first_pass or :second_pass
 @param block Proc
977507
def subscribe_signal(signal_name, step=:first_pass, &block)
      key = SecureRandom.hex(5)
      @subscriptions ||= Hash.new()
      @subscriptions[signal_name] ||= Hash.new
      @subscriptions[signal_name][key] = block
      key
    end
9820
def method_missing(name, &block)
      @formats.push([name, block || proc {}]) unless @formats.any? {|n,b| n == name}
    end
625263
def run(*steps):
    
    if not steps:
        return

    task = None
    run._sigint = False  # function attr to allow setting from closure
    loop = asyncio.get_event_loop()

    def abort():
        task.cancel()
        run._sigint = True

    added = False
    try:
        loop.add_signal_handler(signal.SIGINT, abort)
        added = True
    except (ValueError, OSError, RuntimeError) as e:
        # add_signal_handler doesn't work in a thread
        if 'main thread' not in str(e):
            raise
    try:
        for step in steps:
            task = loop.create_task(step)
            loop.run_until_complete(asyncio.wait([task], loop=loop))
            if run._sigint:
                raise KeyboardInterrupt()
            if task.exception():
                raise task.exception()
        return task.result()
    finally:
        if added:
            loop.remove_signal_handler(signal.SIGINT)
245402
public void signal(boolean signal_all) {
        lock.lock();
        try {
            if(signal_all)
                cond.signalAll();
            else
                cond.signal();
        }
        finally {
            lock.unlock();
        }
    }
42233
public void trigger(DelegateExecution execution, String signalName, Object signalData) {
    innerActivityBehavior.trigger(execution, signalName, signalData);
  }
1272164
def call(*args, &block)
      self.result = defined?(super) ? super(*args, &block) : to_proc.call(*args, &block)
    end
686735
def step(steps = 1)
      steps.times do
        @instruction = Instruction.new(@memory.read(@PC))
        @PC += 1

        op  = @instruction.op
        a   = get_operand(@instruction.a)
        b   = get_operand(@instruction.b) if @instruction.b

        if @skip
          @skip = false
        else
          if b # Basic Instruction
            result = self.send(op, a.value, b.value)
          else # Non-Basic Instruction
            result = self.send(op, a.value)
          end
          a.write(result) if result
        end

        # Notify observers
        changed
        notify_observers(self)
      end
    end
1057807
def bind(proc=nil, &block)
      (proc || block).call(value).tap do |result|

        # def parent_name(obj)
        #   parts = obj.class.name.split('::')
        #   if parts.count > 1
        #     parts[0..-2].join('::')
        #   else
        #     parts[0]
        #   end
        # end

        # self_parent  = parent_name(self)
        # other_parent = parent_name(result)
        # raise NotMonadError, "Expected #{result.inspect} to be an #{other_parent}" unless self_parent == other_parent

        parent = self.class.superclass === Object ? self.class : self.class.superclass
        raise NotMonadError, "Expected #{result.inspect} to be an #{parent}" unless result.is_a? parent
      end
    end
663666
private void sendNextSketchBlock() {
        byte[] rawBlock = sketchBlocksToSend.get(currSketchBlockNum);
        Buffer block = new Buffer();
        block.write(rawBlock);
        sendMessage(BeanMessageID.BL_FW_BLOCK, block);

        resetSketchBlockSendTimeout();

        int blocksSent = currSketchBlockNum + 1;
        int totalBlocks = sketchBlocksToSend.size();
        onSketchUploadProgress.onResult(UploadProgress.create(blocksSent, totalBlocks));

        currSketchBlockNum++;
        if ( currSketchBlockNum >= sketchBlocksToSend.size() ) {
            resetSketchUploadState();
        }
    }
299488
public void goToStep(int step) {
        for (int i = 0; i < getWidgetCount(); i++) {
            Widget w = getWidget(i);
            if (w instanceof MaterialStep) {
                ((MaterialStep) w).setActive(false);
            }
        }

        Widget w = getWidget(step - 1);
        if (w instanceof MaterialStep) {
            ((MaterialStep) w).setActive(true);
        }
        setCurrentStepIndex(step - 1);
    }
979962
function(context, callback, binds) {
		var instance = new Instance(this);
		var count = 0,
			binded = false;
		for (var i = 1, len = this.parts.length; i < len; i = i + 2) {
			var block = this.parts[i];
			if (block.binded) {
				binded = true;
				var h = handler(instance, context, block.func, count, callback),
					dep = block.dep;
				for (var j = 0, lenJ = dep.length; j < lenJ; j++)
					context.subscribe(dep[j], h, false, instance.binds);
			}
			count++;
		}
		if (binded && binds)
			binds.push(unsub(instance));
		return instance;
	}
829040
def action_signal_triggered(self, model, prop_name, info):
        
        msg = info.arg
        # print("action_signal_triggered state: ", self.state.state_id, model, prop_name, info)
        if msg.action.startswith('sm_notification_'):
            return
        # # affected child propagation from state
        # if hasattr(self, 'states'):
        #     for m in info['arg'].affected_models:
        #         print(m, self.states)
        #         print([m is mm for mm in self.states.values()], [m in self for m in info['arg'].affected_models], \)
        #             [m in self.states.values() for m in info['arg'].affected_models]
        if any([m in self for m in info['arg'].affected_models]):
            if not msg.action.startswith('parent_notification_'):
                new_msg = msg._replace(action='parent_notification_' + msg.action)
            else:
                new_msg = msg
            for m in info['arg'].affected_models:
                # print('???propagate it to', m, m.parent)
                if isinstance(m, AbstractStateModel) and m in self:
                    # print('!!!propagate it from {0} to {1} {2}'.format(self.state.state_id, m.state.state_id, m))
                    m.action_signal.emit(new_msg)

        if msg.action.startswith('parent_notification_'):
            return

        # recursive propagation of action signal TODO remove finally
        if self.parent is not None:
            # Notify parent about change of meta data
            info.arg = msg
            # print("DONE1", self.state.state_id, msg)
            self.parent.action_signal_triggered(model, prop_name, info)
            # print("FINISH DONE1", self.state.state_id, msg)
        # state machine propagation of action signal (indirect) TODO remove finally
        elif not msg.action.startswith('sm_notification_'):  # Prevent recursive call
            # If we are the root state, inform the state machine model by emitting our own meta signal.
            # To make the signal distinguishable for a change of meta data to our state, the change property of
            # the message is prepended with 'sm_notification_'
            # print("DONE2", self.state.state_id, msg)
            new_msg = msg._replace(action='sm_notification_' + msg.action)
            self.action_signal.emit(new_msg)
            # print("FINISH DONE2", self.state.state_id, msg)
        else:
            # print("DONE3 NOTHING")
            pass
528196
def block(self, signals=None, isBlocked=True):
        
        if signals:
            try:
                if isinstance(signals, basestring):
                    signals = [signals]
            except NameError:
                if isinstance(signals, str):
                    signals = [signals]

        signals = signals or self.keys()

        for signal in signals:
            if signal not in self:
                raise RuntimeError("Could not find signal matching %s" % signal)
            self[signal].block(isBlocked)
482865
protected function process_block_rule($name, $block) {
        $this->rulestack[] = array('callback' => method_exists($this, $name."_block_rule") ? $name."_block_rule" : null, 'rule' => $block);

        $this->string = preg_replace_callback($block['expression'], array($this, 'block_callback'), $this->string);

        array_pop($this->rulestack);
    }
267483
public Object invokeStep(String remoteStepInvokerId, String stepTokenId, List<String> params) throws Exception {
        try {
            //call the remote method
            Object[] args = {remoteStepInvokerId, stepTokenId, ChorusContext.getContext().getSnapshot(), params};
            String[] signature = {"java.lang.String", "java.lang.String", "java.util.Map", "java.util.List"};
            log.debug(String.format("About to invoke step (%s) on MBean (%s)", remoteStepInvokerId, objectName));
            JmxStepResult r = (JmxStepResult) mBeanServerConnection.invoke(objectName, "invokeStep", args, signature);

            //update the local context with any changes made remotely
            Map newContextState = r.getChorusContext();
            ChorusContext.resetContext(newContextState);

            //return the result which the remote step method returned
            return r.getResult();
        } catch (MBeanException e) {
            throw e.getTargetException();
        }
    }
113868
def set_step(self, value, block_events=False):
        
        if block_events: self.block_events()
        self._widget.setSingleStep(value)
        if block_events: self.unblock_events()
105218
def emit(signal, *args, **kwargs):
    
    for callback in set(receivers[signal]):  # Make a copy in case of any ninja signals
        _call(callback, args=args, kwargs=kwargs)