Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}));
}
var Fiber = require('fibers');
try {
Fiber.prototype.run.call(null);
} catch (err) {
console.log('pass');
}
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);
};
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);
};
}
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);
};
}
'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) {
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);
};