channel

Conditional Timeout

一个人想着一个人 提交于 2021-02-16 21:07:45
问题 I have some code, there are 3 timers, GracefulExecutionTimeout - total running time WaitTimeout - time to initial wait for first message IdleTimeout - time to wait for subsequent messages If any of the timers are reached the app should cleanly exit. I have it working below msgs := make(chan string) go func() { time.Sleep(time.Second) msgs <- "test" }() // graceful max execution time gracefulMaxTimeout := time.Second * time.Duration(10) gracefulMaxTimer := time.NewTimer(gracefulMaxTimeout) //

Conditional Timeout

旧时模样 提交于 2021-02-16 20:58:46
问题 I have some code, there are 3 timers, GracefulExecutionTimeout - total running time WaitTimeout - time to initial wait for first message IdleTimeout - time to wait for subsequent messages If any of the timers are reached the app should cleanly exit. I have it working below msgs := make(chan string) go func() { time.Sleep(time.Second) msgs <- "test" }() // graceful max execution time gracefulMaxTimeout := time.Second * time.Duration(10) gracefulMaxTimer := time.NewTimer(gracefulMaxTimeout) //

How to get the number of elements in an unbuffered channel

回眸只為那壹抹淺笑 提交于 2021-02-10 07:29:07
问题 I am in a situation where my program is deadlocking and I want to debug this and tell how many elements are in an unbuffered channel, is there any way to do this in Go? The following code does not output a 2 as I would expect (further it deadlocks, which is also something I cannot find a reason for) package main import "fmt" func main() { channel := make(chan string) done_channel := make(chan bool) go func() { channel <- "value" channel <- "value" fmt.Println(len(channel)) done_channel <-

Sending directly from one channel to another

吃可爱长大的小学妹 提交于 2021-02-07 08:43:28
问题 I stumbled upon what I found to be surprising behavior when sending from one channel directly to another channel: package main import ( "fmt" ) func main() { my_chan := make(chan string) chan_of_chans := make(chan chan string) go func() { my_chan <- "Hello" }() go func() { chan_of_chans <- my_chan }() fmt.Println(<- <- chan_of_chans) } Go Playground I expected <- my_chan to send "Hello" type string . However, it sends type chan string and my code runs fine. This means that what is being (

Sending directly from one channel to another

自作多情 提交于 2021-02-07 08:42:07
问题 I stumbled upon what I found to be surprising behavior when sending from one channel directly to another channel: package main import ( "fmt" ) func main() { my_chan := make(chan string) chan_of_chans := make(chan chan string) go func() { my_chan <- "Hello" }() go func() { chan_of_chans <- my_chan }() fmt.Println(<- <- chan_of_chans) } Go Playground I expected <- my_chan to send "Hello" type string . However, it sends type chan string and my code runs fine. This means that what is being (

Netty, concurrent writeAndFlush

会有一股神秘感。 提交于 2021-01-29 12:31:33
问题 Lets say we have some kind of pub/sub protocol. When someone is connecting and subscribing, we can save channel in Map, List or ChannelGroup: @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { super.channelActive(ctx); log.debug("Client connected: {}", ctx.channel().remoteAddress()); clients.add(ctx); } After that, when some message has come or some event has happened, I can notify clients: @Override public void channelRead(ChannelHandlerContext ctx, Object msg)

Netty, concurrent writeAndFlush

人走茶凉 提交于 2021-01-29 08:52:50
问题 Lets say we have some kind of pub/sub protocol. When someone is connecting and subscribing, we can save channel in Map, List or ChannelGroup: @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { super.channelActive(ctx); log.debug("Client connected: {}", ctx.channel().remoteAddress()); clients.add(ctx); } After that, when some message has come or some event has happened, I can notify clients: @Override public void channelRead(ChannelHandlerContext ctx, Object msg)

Golang Goroutine Error “all goroutines are asleep - deadlock!”

眉间皱痕 提交于 2021-01-28 05:50:32
问题 I am trying to make a code to scan from a folder link all my files and make a "top 10" by his size with also a regexp based on his content and his name. file. By it content, I make channels with goroutines but I dont understand why each time my goroutines are locked. Here is my code: package main import ( "flag" "fmt" "io/ioutil" "regexp" "runtime" "sort" "sync" "time" ) var rName = ".php" var rContent = "php" var maxSize, minSize int64 var files_ten []File func main() { start := time.Now()

Add channel to category by name

强颜欢笑 提交于 2020-12-30 07:42:31
问题 var server = message.guild; for (var i = 0; i < server.channels.array().length; i++) { server.channels.array()[i].delete(); } server.createChannel("Text Channels", "category"); server.createChannel('general', "text"); I am trying to make the text channel 'general` go into the category 'Text Channels' All the solutions I have found rely on you knowing the categories id . I was wondering if there is a way I could get the category id , or else move general into "Text Channels" simply by its name

Add channel to category by name

白昼怎懂夜的黑 提交于 2020-12-30 07:42:05
问题 var server = message.guild; for (var i = 0; i < server.channels.array().length; i++) { server.channels.array()[i].delete(); } server.createChannel("Text Channels", "category"); server.createChannel('general', "text"); I am trying to make the text channel 'general` go into the category 'Text Channels' All the solutions I have found rely on you knowing the categories id . I was wondering if there is a way I could get the category id , or else move general into "Text Channels" simply by its name