Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fibers

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fibers

Cooperative multi-tasking for Javascript

  • 1.0.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
136K
decreased by-9.13%
Maintainers
1
Weekly downloads
 
Created

What is fibers?

The 'fibers' npm package provides an implementation of fibers, which are a form of cooperative multitasking. This allows you to write asynchronous code in a synchronous style, making it easier to manage complex asynchronous flows.

What are fibers's main functionalities?

Creating and running a fiber

This code demonstrates how to create and run a fiber. The fiber prints a message, yields control back to the main program, and then resumes to print another message.

const Fiber = require('fibers');

Fiber(function() {
  console.log('Fiber started');
  Fiber.yield();
  console.log('Fiber resumed');
}).run();

console.log('Main program');

Yielding and resuming

This example shows how to yield and resume a fiber. The fiber yields control back to the main program, which then resumes the fiber.

const Fiber = require('fibers');

const fiber = Fiber(function() {
  console.log('Fiber started');
  Fiber.yield();
  console.log('Fiber resumed');
});

fiber.run();
console.log('Main program');
fiber.run();

Passing data between fibers

This code demonstrates how to pass data between the main program and a fiber. The fiber receives initial data, yields a response, and then resumes with data from the main program.

const Fiber = require('fibers');

const fiber = Fiber(function(data) {
  console.log('Fiber received:', data);
  const response = Fiber.yield('Fiber response');
  console.log('Fiber resumed with:', response);
});

const response = fiber.run('Initial data');
console.log('Main program received:', response);
fiber.run('Main program response');

Other packages similar to fibers

Keywords

FAQs

Package last updated on 08 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc