How to use the fibers.current 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 ybogdanov / node-sync / lib / sync.js View on Github external
var fiber = Fiber(function(){
        
        Sync.stat.activeFibers++;
        
        var fiber = Fiber.current,
            result,
            error;
        
        // Set id to fiber
        fiber.id = Sync.stat.totalFibers;
        
        // Save the callback to fiber
        fiber.callback = callback;
        
        // Register trace error to the fiber
        fiber.traceError = traceError;
        
        // Initialize scope
        fiber.scope = {};
        
        // Assign parent fiber
github meteor / promise / test / tests.js View on Github external
promise = promise.then(function (count) {
        assert.ok(Fiber.current instanceof Fiber);
        assert.notStrictEqual(Fiber.current, originalFiber);
        return count + 1;
      });
    }
github ybogdanov / node-sync / test / future.js View on Github external
function syncFunctionTimeout(t) {
    var fiber = Fiber.current;
    setTimeout(function(){
        fiber.run('result');
    }, t)
    return Fiber.yield();
}
github nodeontrain / trainjs / lib / helpers / asset_tag_helper.js View on Github external
stylesheet_link_tag = function(filename, options) {
	var opt_str = "";
	if (typeof options !== "undefined") {
		for (var k in options) {
			opt_str = opt_str + " " + k + "=" + options[k];
		}
	}
	if (filename == "application") {
		var filepath = ROOT_APP + '/app/assets/stylesheets/application.css';
		var input = fs.createReadStream(filepath);
		var remaining = '';
		var html = "";
		var fiber = Fiber.current;
		input.on('data', function(data) {
			remaining += data;
			var index = remaining.indexOf('\n');
			while (index > -1) {
				var line = remaining.substring(0, index);
				if (line.split('*=')[1]) {
					var require_str = jtrain.trim(line.split('*=')[1]);
					if (require_str == "require_tree .") {
						css_files = fs.readdirSync(ROOT_APP + '/app/assets/stylesheets');
						for	(var i = 0; i < css_files.length; i++) {
							if (css_files[i] != "application.css")
								html += ''
						}
					} else if (require_str == "require_self") {
						html += ''
					}
github jpaulm / jsfbp / core / InputPortArray.js View on Github external
InputPortArray.openInputPortArray = function(name) {
  var proc = Fiber.current.fbpProc; 
  var namey = proc.name + '.' + name;
  var hi_index = -1;  
  var array = [];

  var re = new RegExp(namey + '\\[(\\d+)\\]');  

  for (var i = 0; i < proc.inports.length; i++) {   
    var namex = re.exec(proc.inports[i][0]);   

    if (namex != null && namex.index == 0) {
        hi_index = Math.max(hi_index, namex[1]);
        array[namex[1]] = proc.inports[i][1];
    }
  }
  if (hi_index == -1) {
    console.log('Port ' + proc.name + '.' + name + ' not found');
github jpaulm / jsfbp / core / trace.js View on Github external
module.exports = function(message) {
  if(global.trace) {
  var calledAs = "";
  if(this && this.name) {
    calledAs = this.name;
  }
  var fiberProc = "no-fiber";
  if(Fiber.current) {
    if(Fiber.current.fbpProc) {
      fiberProc = Fiber.current.fbpProc.name;
    } else {
      fiberProc = "runtime";
    }
  }

  var tag = "[" + fiberProc + "->" + calledAs + "]";
  if(fiberProc === calledAs) {
    tag = "[" + calledAs + "]";
  } else if (!calledAs) {
    tag = "[" + fiberProc + "]";
  }
    
      console.log(tag + ' ' + message);
  }
github nodeontrain / trainjs / lib / object_mapper / mongodb / train.model.js View on Github external
global[modelName].prototype.update_attributes = function (data) {
				for (var k in data) {
					this[k] = data[k];
				}
				var fiber = Fiber.current;
				this.save(function (err) {
					if (err) return fiber.run(err);
					fiber.run(true);
				});
				return Fiber.yield();
			};
			global[modelName].prototype.destroy = function () {
github Sage / f-promise / src / index.ts View on Github external
export function withContext(fn: () => T, cx: any): T {
    if (!fibers.current) throw new Error('withContext(fn) not allowed outside run()');
    const oldContext = globals.context;
    globals.context = cx || Object.create(oldContext);
    try {
        return fn();
    } finally {
        globals.context = oldContext;
    }
}
github yortus / asyncawait / yield.js View on Github external
var yield_ = function (expr) {
    Fiber.current['value'].resolve(expr);
    Fiber.current['done'].resolve(false);
    Fiber.yield();
};
module.exports = yield_;
github yortus / asyncawait / yield.js View on Github external
var yield_ = function (expr) {
    Fiber.current['value'].resolve(expr);
    Fiber.current['done'].resolve(false);
    Fiber.yield();
};
module.exports = yield_;