<commit_before>var events                    = require('events');
var util                      = require('util');

var ffi                       = require('ffi');
var $                         = require('NodObjC');
var reemit                    = require('re-emitter');

var PeripheralManagerDelegate = require('./peripheral-manager-delegate');
var $util                     = require('./util');

var localAddress              = require('./local-address');
var uuidToAddress             = require('./uuid-to-address');


$.import('Foundation');
$.import('CoreBluetooth');

var libdispatch = ffi.Library('/usr/lib/system/libdispatch', {
  'dispatch_queue_create': ['pointer', ['string', 'int']]
});


$.CBPeripheralManager.addMethod('handleMTUChangedSwizzled:', 'v@:@', function($self, $_cmd, $event) {
  $self('handleMTUChangedSwizzled', $event);

  $self('delegate')('peripheralManager', $self, 'centralDidExchangeMTU', $event);
});

$.CBPeripheralManager.getInstanceMethod('handleMTUChanged:').exchangeImplementations($.CBPeripheralManager.getInstanceMethod('handleMTUChangedSwizzled:'));

function PeripheralManager() {
  this.delegate  = new PeripheralManagerDelegate();
  this._services = [];
  this._pendingRequests = {};

  reemit(this.delegate, this, [
    'stateUpdate',
    'advertisingStart'
  ]);

  this.delegate.on('serviceAdded', this._onServiceAdded.bind(this));
  this.delegate.on('readRequest', this._onReadRequest.bind(this));
  this.delegate.on('writeRequests', this._onWriteRequests.bind(this));
  this.delegate.on('mtuChange', this._onMtuChange.bind(this));
  this.delegate.on('subscribe', this._onSubscribe.bind(this));
  this.delegate.on('unsubscribe', this._onUnsubscribe.bind(this));

  localAddress(function(address) {
    if (address) {
      this.emit('address', address);<commit_msg>- improve handleMTUChangedSwizzled handling by using process.nextTick<commit_after>var events                    = require('events');
var util                      = require('util');

var ffi                       = require('ffi');
var $                         = require('NodObjC');
var reemit                    = require('re-emitter');

var PeripheralManagerDelegate = require('./peripheral-manager-delegate');
var $util                     = require('./util');

var localAddress              = require('./local-address');
var uuidToAddress             = require('./uuid-to-address');


$.import('Foundation');
$.import('CoreBluetooth');

var libdispatch = ffi.Library('/usr/lib/system/libdispatch', {
  'dispatch_queue_create': ['pointer', ['string', 'int']]
});


$.CBPeripheralManager.addMethod('handleMTUChangedSwizzled:', 'v@:@', function($self, $_cmd, $event) {
  $self('delegate')('peripheralManager', $self, 'centralDidExchangeMTU', $event);

  process.nextTick(function() {
    $self('handleMTUChangedSwizzled', $event);
  });
});

$.CBPeripheralManager.getInstanceMethod('handleMTUChanged:').exchangeImplementations($.CBPeripheralManager.getInstanceMethod('handleMTUChangedSwizzled:'));

function PeripheralManager() {
  this.delegate  = new PeripheralManagerDelegate();
  this._services = [];
  this._pendingRequests = {};

  reemit(this.delegate, this, [
    'stateUpdate',
    'advertisingStart'
  ]);

  this.delegate.on('serviceAdded', this._onServiceAdded.bind(this));
  this.delegate.on('readRequest', this._onReadRequest.bind(this));
  this.delegate.on('writeRequests', this._onWriteRequests.bind(this));
  this.delegate.on('mtuChange', this._onMtuChange.bind(this));
  this.delegate.on('subscribe', this._onSubscribe.bind(this));
  this.delegate.on('unsubscribe', this._onUnsubscribe.bind(this));

  localAddress(function(address) {
    if (address) {
      this.emit('address', address);
{'fraction_non_alphanumeric': 0.16541353383458646, 'fraction_numerical': 0.0, 'mean_word_length': 3.9207397622192866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207914', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1061, 'n_words': 156}