1.0.2 • Published 6 months ago

typescript-channel v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
6 months ago

LINK TEST

channel = new Channel<number>();

const valuesToSend = [1, 2, 3];
    const receivedValues: number[] = [];

    const receivePromise = async () => {
      while (channel.State != ChannelState.EMPTY) {
        try {
          const value = await channel.receive();
          receivedValues.push(value);
        } catch {
          break; // Stop when the channel is closed
        }
      }
    };

    // Send values to the channel
    for (const value of valuesToSend) {
      channel.send(value);
    }

    // Start the receive operation in the background
    await receivePromise();

    channel.close(); // Close the channel when done

    // Wait for the background receive operation to finish
    await new Promise((resolve) => setTimeout(resolve, 0));

    expect(receivedValues).toEqual(valuesToSend);
1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago