first create monitor object, the callback is executed when the monitor constructor call this.ready
350230
function (emits, message, daemonPid) {
    var monitor = new Monitor(message, options, daemonPid, shutdown, child, function () {

      // emit events before starting child
      Object.keys(emits).forEach(function (name) {
        // skip the process event until the child spawns
        if (name === 'process') return;

        monitor.emit.apply(monitor, [name].concat( emits[name] ));
      });

      // spawn child when monitor is ready
      child.spawn();

      // start pumping streams to monitor
      child.pump(monitor);
    });

    // once the child has started emit the process event
    child.once('start', function () {
      monitor.pid.process = child.pid;
      monitor.emit.apply(monitor, ['process'].concat( emits.process ));
    });

    // relay stop and restart to process event on monitor
    child.on('stop', function () {
      monitor.pid.process = null;

      // Do not emit if the deamon is in restart mode
      if (daemonInRestart) return;
      monitor.emit('process', 'stop');
    });
    child.on('restart', function () {
      monitor.pid.process = child.pid;
      monitor.emit('process', 'restart');
    });
  }
1355993
function(handler) {
      var t = this;
      if (t.monitor && t.monitor.isConnected()) {
        setTimeout(function(){handler(t.monitor);},0);
      }
      else {
        t.connectHandlers.push(handler);
      }
    }
211466
@Validate
    public void start() {
        module = new SimpleModule(MonitorExtension.class.getName());
        module.addSerializer(MonitorExtension.class, new JsonSerializer<MonitorExtension>() {
            @Override
            public void serialize(MonitorExtension monitorExtension, JsonGenerator jsonGenerator,
                                  SerializerProvider serializerProvider) throws IOException {
                jsonGenerator.writeStartObject();
                jsonGenerator.writeStringField("label", monitorExtension.label());
                jsonGenerator.writeStringField("url", monitorExtension.url());
                jsonGenerator.writeStringField("category", monitorExtension.category());
                jsonGenerator.writeEndObject();
            }
        });
        repository.register(module);
    }
1243313
private void initialize(Handler callbackHandler, int threadPoolSize) {
		mDownloadDispatchers = new DownloadDispatcher[threadPoolSize];
		mDelivery = new CallBackDelivery(callbackHandler);
	}
1109428
protected void init() {
        // create a synchronisation task which makes sure that the change requested by
        // the internal future has at one time been synchronized to the remote
        synchronisationFuture = GlobalCachedExecutorService.submit(() -> {
            dataProvider.addDataObserver(notifyChangeObserver);
            try {
                dataProvider.waitForData();
                T result = internalFuture.get();
                waitForSynchronization(result);
            } catch (CouldNotPerformException ex) {
                ExceptionPrinter.printHistory("Could not sync with internal future!", ex, logger);
            } finally {
                dataProvider.removeDataObserver(notifyChangeObserver);
            }
            return null;
        });
    }
1024084
function ready() {
            if (!readyFired) {
                // this must be set to true before we start calling callbacks
                readyFired = true;
                for (var i = 0; i < readyList.length; i++) {
                    // if a callback here happens to add new ready handlers,
                    // the docReady() function will see that it already fired
                    // and will schedule the callback to run right after
                    // this event loop finishes so all handlers will still execute
                    // in order and no new ones will be added to the readyList
                    // while we are processing the list
                    readyList[i].fn.call(window, readyList[i].ctx);
                }
                // allow any closures held by these functions to free
                readyList = [];
            }
        }
170676
public void startMonitoring() {
        if (debug) LogD("");
        long start = settings.getLong(KEY_MONITOR_START, 0);
        if (start != 0) {
            if (debug) LogD("Monitor error.  called before end. Adding the result");
            endMonitoring();
        }
        editor.putLong(KEY_MONITOR_START, System.currentTimeMillis());
        commitEditor();
    }
717979
@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		EVENT_CONFIGURATION = EventLinker.Configuration.newInstance(this);
	}
451660
function() {
      var t = this,
          branches = t.model.get('branches'),
          leaves = t.model.get('leaves');

      // Determine if we should connect a monitor to this node
      //
      // Connect a monitor if:
      // * There isn't one already connected, and
      // * There's a monitor definition available, and
      // * We're open, or
      // *   preFetch is selected, and
      // *     we have no parent or our parent is open
      //
      // ** Is there any way to make this logic simpler?
      var shouldConnect = !t.model.hasMonitor()
        && t.options.monitorParams
        && (t.model.get('isOpen')
          || (t.options.preFetch
            && (!t.options.parentView
              || t.options.parentView.model.get('isOpen'))));

      // Connect to the monitor if we've determined we should
      if (shouldConnect) {

        // If there isn't any model data to display, show Loading...
        if (!branches || !leaves) {
          t.loading = $('<li>Loading...</li>').appendTo(t.$el);
        }

        // Build and connect the Monitor
        var initParams = _.extend(
          {},
          t.options.monitorParams.initParams || {},
          {path:t.options.path}
        );
        var monitorParams = _.extend(
          {},
          t.options.monitorParams,
          {initParams: initParams}
        );
        t.monitor = new Monitor(monitorParams);
        t.model.attachMonitor(t.monitor);

        // Call our handlers once connected
        t.monitor.on('connect', function(){
          setTimeout(function(){
            for (var i in t.connectHandlers) {
              var handler = t.connectHandlers[i];
              handler(t.monitor);
            }
          },10);
        });

        // Connect the monitor and process errors.  Successes will change
        // the underlying data model (or not), causing a re-render.
        t.monitor.connect(function(error) {

          // Remove the Loading... message
          if (t.loading) {
            t.loading.remove();
            t.loading = null;
          }

          // Handle errors
          if (error) {
            $('<li>(connection problem)</li>').appendTo(t.$el);
            console.error('TreeView monitor connection problem:', error, t.monitor);

            // Detach the problem monitor so it'll have another chance
            // if the user opens/closes the branch.
            t.model.detachMonitor();
          }

        });
      }
    }
52525
synchronized void rel_monitor() {
	Util.out4.println("In rel_monitor(), used = " + used + ", ctr = " + locked_ctr);
	if (used == true) {
	    locked_ctr--;
	    if (locked_ctr == 0) {
		Util.out4.println("Signalling !");
		used = false;
		// locking_thread = NULL;
		notify();
	    }
	}
    }
28723
function execute(req, res) {
  req.conn.monitor(this);
  res.send(null, Constants.OK);
}
1194195
function onChildStart (monitor, data) {
      result = {
        monitor: monitor,
        process: monitor.child,
        data: data,
        pid: monitor.childData.pid,
        pkg: app
      };

      haibu.emit(['drone', 'start'], 'info', {
        process: data,
        pkg: result.pkg
      });
    }
1185539
public void monitorEnter(Local<?> monitor) {
        addInstruction(new ThrowingInsn(Rops.MONITOR_ENTER, sourcePosition,
                RegisterSpecList.make(monitor.spec()), catches));
    }
74014
function() {
      var t = this,
          pageView = UI.pageView,
          pageModel = pageView.model,
          view = t.view,
          getMonitor = function(id) {return pageView.getMonitor(id);},
          monitor = t.model.get('monitor');

      // Execute the onInit
      try {
        eval(t.model.get('onInit'));
      }
      catch (e) {
        log.error('onInitException', t.logCtxt, e);
        alert("Component onInit exception.  See error log for more information.");
      }
    }
284705
public void monitor(Monitor target) {
        log.info("starting monitor: {}", target);

        try {
            target.getMonitorDriver(props, configService).run();

        } catch (Exception e) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            PrintStream error = new PrintStream(out);

            error.println("Error in MonitorsDriver: " + e.getMessage());
            e.printStackTrace(error);

            error.flush();
            IOUtils.closeQuietly(out);

            String msg = new String(out.toByteArray());
            log.error(msg);
            sendEmail("Management Console Monitors Error", msg);
        }
    }
949298
def do_init(self, handler):
        
        self.waiting = True
        self.exc_info = None
        self.handler = handler
1344569
function readyBenchmark() {
  if (cluster.isWorker) {
    process.on('message', function(message) {
      switch (message) {
        case 'start':
          startBenchmark();
          break;
      }
    })
    process.send('ready');
  } else {
    startBenchmark()
  }
}