Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@effection/channel

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/channel

MPMC Channel implementation for effection

package-json-version-import
Source
npmnpm
Version
2.0.0-package-json-version-import.1629635798385
Version published
Weekly downloads
4.5K
-25.99%
Maintainers
1
Weekly downloads
 
Created
Source

@effection/channel

A multi producer, multi consumer unbounded channel for Effection. Channels are useful for communicating between different parts of a system, for building pubsub buses, or a whole lot of other synchronization needs.

Sending to a channel is synchronous and does not require the sender to be running in an effection context. However, reading from a channel can only be done through operations.

Because of the synchronous nature of sends, channels are unbounded in size, which means that they cannot handle backpressure. As such, channels should be used more as a synchronization mechanism, rather than a high-throughput system.

Usage

A basic example:

import { createChannel } from '@effection/channel';
import { main } from '@effection/main';
import { sleep } from '@effection/core';

main(function*() {
  let channel = createChannel();

  spawn(function*() {
    while(true) {
      yield sleep(1000);
      channel.send({ message: "ping" });
    }
  });

  let subscription = yield channel.subscribe();

  while(true) {
    let { value } = yield subscription.next();
    console.log("value:", value);
  }
});

FAQs

Package last updated on 22 Aug 2021

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