How to use the fibers.prototype function in fibers

To help you get started, we’ve selected a few fibers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github laverdet / node-fibers / test / fibonacci.js View on Github external
function Fibonacci() {
	return Fiber.prototype.run.bind(Fiber(function() {
    Fiber.yield(0); // F(0) -> 0
    var prev = 0, curr = 1;
    while (true) {
      Fiber.yield(curr);
      var tmp = prev + curr;
      prev = curr;
      curr = tmp;
    }
  }));
}
github laverdet / node-fibers / test / bad-context.js View on Github external
var Fiber = require('fibers');

try {
	Fiber.prototype.run.call(null);
} catch (err) {
	console.log('pass');
}
github steedos / workflow / packages / kadira-master / lib / hijack / async.js View on Github external
var Fibers = require('fibers');

var originalYield = Fibers.yield;
Fibers.yield = function() {
  var kadiraInfo = Kadira._getInfo();
  if(kadiraInfo) {
    var eventId = Kadira.tracer.event(kadiraInfo.trace, 'async');;
    if(eventId) {
      Fibers.current._apmEventId = eventId;
    }
  }

  return originalYield();
};

var originalRun = Fibers.prototype.run;
Fibers.prototype.run = function(val) {
  if(this._apmEventId) {
    var kadiraInfo = Kadira._getInfo(this);
    if(kadiraInfo) {
      Kadira.tracer.eventEnd(kadiraInfo.trace, this._apmEventId);
      this._apmEventId = null;
    }
  }
  return originalRun.call(this, val);
};
github kschingiz / meteor-elastic-apm / hijack / async.js View on Github external
Fibers.yield = function() {
    const transaction = apm.currentTransaction;
    if (transaction) {
      const span = apm.startSpan();
      if (span) {
        span.name = "async";
        span.type = "async";
        Fibers.current._apmSpan = span;
      }
    }

    return originalYield();
  };

  const originalRun = Fibers.prototype.run;
  Fibers.prototype.run = function(val) {
    if (this._apmSpan) {
      const span = this._apmSpan;
      span.end();
      this._apmSpan = null;
    }
    return originalRun.call(this, val);
  };
}
github kschingiz / meteor-elastic-apm / hijack / async.js View on Github external
const originalYield = Fibers.yield;
  Fibers.yield = function() {
    const transaction = apm.currentTransaction;
    if (transaction) {
      const span = apm.startSpan();
      if (span) {
        span.name = "async";
        span.type = "async";
        Fibers.current._apmSpan = span;
      }
    }

    return originalYield();
  };

  const originalRun = Fibers.prototype.run;
  Fibers.prototype.run = function(val) {
    if (this._apmSpan) {
      const span = this._apmSpan;
      span.end();
      this._apmSpan = null;
    }
    return originalRun.call(this, val);
  };
}
github jpaulm / jsfbp / core / runtimes / FiberRuntime / index.js View on Github external
'use strict';

var Fiber = require('fibers'),
  IIPConnection = require('../../IIPConnection'),
  Process = require('../../Process'),
  _ = require('lodash'),
  trace = require('../../trace'),
  Enum = require('../../Enum');

Fiber.prototype.fbpProc = null;

var FiberRuntime = module.exports = function () {
  this._queue = [];
  this._openProcessCount = 0;
};


/*
 * A general method for queing a process for an upcoming tick
 * Guarantees that processes will not be added to the queue if it is already queued
 */
FiberRuntime.prototype.pushToQueue = function (process) {
  var processInQueue = _.some(this._queue, function (queuedProcess) {
    return queuedProcess.name === process.name;
  });
  if (!processInQueue) {
github steedos / workflow / packages / kadira-master / lib / hijack / async.js View on Github external
var originalYield = Fibers.yield;
Fibers.yield = function() {
  var kadiraInfo = Kadira._getInfo();
  if(kadiraInfo) {
    var eventId = Kadira.tracer.event(kadiraInfo.trace, 'async');;
    if(eventId) {
      Fibers.current._apmEventId = eventId;
    }
  }

  return originalYield();
};

var originalRun = Fibers.prototype.run;
Fibers.prototype.run = function(val) {
  if(this._apmEventId) {
    var kadiraInfo = Kadira._getInfo(this);
    if(kadiraInfo) {
      Kadira.tracer.eventEnd(kadiraInfo.trace, this._apmEventId);
      this._apmEventId = null;
    }
  }
  return originalRun.call(this, val);
};