🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.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

Source
npmnpm
Version
2.0.0-side-effects.1628154559925
Version published
Maintainers
1
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 05 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