Questions tagged [channel]

A communication construct enabling sending of objects between execution threads. You may and should use this tag to refer either to the generic programming notion or the specific implementations in various languages or libraries. In the latter case don't forget to add the appropriate tag.

The channel construct is frequently used in multithreading programs to enable safe synchronization of execution threads and communication of objects between them.

When using this tag to refer to the specific implementation in a programming language or library, don't forget to add an additional tag to prevent confusion, for example .

General References :

Wikipedia definition of the channel

Go Language :

The channel is one of the basic constructs of Go and generally behind every parallelization.

As described in Go specification :

A channel provides a mechanism for two concurrently executing functions to synchronize execution and communicate by passing a value of a specified element type.

// creation of a basic synchronous channel of strings
c := make(chan string)

// creation of a channel enabling the buffering of 100 strings before blocking
c := make(chan string, 100)

// sending of a string over the channel
c <- "somestring"

// closing of a channel
close(c)

// reception from a channel. This blocks until a string is available
s := <- c

// blocking loop over a channel until closing
for s := range c {

Java Language :

With Java 1.4, the New IO introduced the channel as an interface with many concrete implementations intended to replace the use of stream in concurrent contexts :

A channel represents an open connection to an entity such as a hardware device, a file, a network socket, or a program component that is capable of performing one or more distinct I/O operations, for example reading or writing.

A channel is either open or closed. A channel is open upon creation, and once closed it remains closed. Once a channel is closed, any attempt to invoke an I/O operation upon it will cause a ClosedChannelException to be thrown. Whether or not a channel is open may be tested by invoking its isOpen method.

Channels are, in general, intended to be safe for multithreaded access as described in the specifications of the interfaces and classes that extend and implement this interface.

2474 questions
0
votes
1 answer

Go program slowing down when increasing number of goroutines

I'm doing a small project for my parallelism course and I have tried it with buffered channels, unbuffered channels, without channels using pointers to slices etc. Also, tried to optimize it as much as possible (not the current state) but I still…
HWDiv
  • 29
  • 2
0
votes
1 answer

discord.js channel only command

Kepps crashing const Discord = require("discord.js") module.exports = { name: 'not-dropping', description: 'sets the dropping status!', if (message.channel.id === '1059798572855476245') { execute(message, args) { …
ilijadivi
  • 3
  • 1
0
votes
0 answers

Go: can't receive syscall.SIGINT in for select loop

I tried to catch the interrupt signal to stop the program, but in the for-select loop, Even if the program is stopped, the default branch will continue to be entered.The code show as below: func main() { c := make(chan os.Signal) …
Pccc
  • 47
  • 4
0
votes
2 answers

Fast producer, slow consumer, bounded channel, reduce the frequency of awakening the producer

I have a producer-consumer scenario¹ based on a bounded Channel. Channel channel = Channel.CreateBounded(10); The items are coming from an RDBMS, to which the producer connects and fetches them one by one. The peculiarity is that I…
0
votes
1 answer

golang Confusing code RabbitMq forever blocked !?

I found an interesting piece of code when using rabbitMQ forever := make(chan bool) go func() { for d := range msgs { log.Printf("Received a message: %s", d.Body) } }() log.Printf(" [*] Waiting for…
wyatt j
  • 13
  • 1
0
votes
1 answer

Channel configuration update for adding new orgs - [Policy] /Channel/Admins not satisfied

I am building a network where I need that nodes will join throuhgout the lifetime of the application and as first implementation I want to change the channel configuration in order to change the policies regarding who needs to sign a configuration…
Rafail K.
  • 365
  • 3
  • 14
0
votes
0 answers

Can't Pass Messages with Servo/Ipc_channel for Rust

I'm stuck on implementing Servo/ipc_channel. I'm looking for a trivial example to do the following. I've read through all the documentation and I just can't find an example that makes sense to me either from the docs or from the test.rs. Here's what…
yosemeti
  • 206
  • 4
  • 15
0
votes
1 answer

How to handle sending and receiving multiple values between 2 tasks?

I need to send and receive multiple values between 2 tasks. I am currently using tokio oneshot channel because I am only dealing with 2 tasks. But I can't seem to re-use the tx probably due to its one message limit. How is this situation handled…
Fast Eater
  • 15
  • 6
0
votes
0 answers

Django channels + HTMX -> notification messages framework

I'd like to implement a notification framework for Django that uses channels/websockets and HTMX. But I don't get how to do that. Some things work, some are extremely complicated n my mind at least. Here's the code: from asgiref.sync import…
nerdoc
  • 1,044
  • 10
  • 28
0
votes
1 answer

How to implement a sorted buffer?

I need to traverse a collection of disjoint folders; each folder is associated to a visited time configurated somewhere in the folder. I then sort the folders, and process the one with the earliest visited time first. Note the processing is…
NilNul
  • 19
  • 5
0
votes
0 answers

Processing Images from a directory. Changing dimensions and channel In python

I have 700 images of radiography split in 2 folders (350 each) within the same directory, the dimensions of all images are 512x512x3 and I need to change it to 64x64x1. I don’t understand how images in black and white have channel 3?? I don’t know…
S_fc
  • 1
  • 2
0
votes
1 answer

Unexpected closed channel in sync::mpsc after rx moved

I'm learning the rust lifetime model. But when using mpsc::channel, the rx is always broken. My questions: When has the rx been dropped? How to use rx in the callback logic? The codes: use tokio::sync::mpsc::channel; #[tokio::main] async fn…
Echo
  • 183
  • 2
  • 11
0
votes
0 answers

how to implement drf simple jwt authentication in django channels

I want to implement my django rest framework user authentication app in django channels I was created one user authentication app in django rest framework and I want to implement these app into django channels
0
votes
0 answers

How to create polity for multiple channels in hyperledger fabric

I have created policy's for one channel but having trouble creating policy for multiple channel. It would be helpful if anyone can even point me to link or vedio to understand policy creations for multiple channels. Creating policy for multiple…
0
votes
1 answer

How to pass arguments into a Channel's queue writer?

I have a background task to be completed; however, I can't write arguments to the Channel. Reason being that the writer only takes in 1 argument. How do queue a function up to be completed with arguments. private readonly Channel
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
1 2 3
99
100