> For the complete documentation index, see [llms.txt](https://roman-sarder.gitbook.io/csp-coffee/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roman-sarder.gitbook.io/csp-coffee/packages-and-api/channels.md).

# Channels

## Overview

We have routines running using our go function, but what if we want those routines to communicate? Let's say that our routine A needs a computation result from routine B in order to complete. That's where you need channels for the purposes of communication. All code related to channels lies in `csp-coffee/channel` package. Let's show an example implementation of the problem above using our library.

```javascript
import { makeChannel } from 'csp-coffeep/channel';
import { go } from 'csp-coffee/go';
import { take, put } from 'csp-coffee/operators';

const ch = makeChannel();

function* adderRoutine (leftValue: number, rightValue: number) {
    yield put(ch, leftValue + rightValue)
}

function* loggerRoutine () {
    const valueToLog: number = yield take(ch);
    console.log(valueToLog) // 5
}

go(adderRoutine, 2, 3);
go(loggerRoutine);

```

Here we have two simple generator functions and a channel. We pass two values to `adderRoutine` which calculates a sum of two numbers and puts it to our channel. `loggerRoutine` waits for a value to appear in the channel, takes it and logs it. That's i


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://roman-sarder.gitbook.io/csp-coffee/packages-and-api/channels.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
