channels

how do I get Mixer channels layout in java

别说谁变了你拦得住时间么 提交于 2019-11-29 12:12:30
I thought I can find anything on this great site but now I seem to face the issue with no answer :) Please help! Thing is, I need to play up to 6 different wav files with 1 channel each into 6 channels supported by system mixer (left, right, surround left, etc). Using 6 different SourceDataLines looks logical but from what I see, Mixer cannot do per-sample synchronisation for them, so I came up with interleaving them in separate thread and use only one SourceDataLine to play it. It works fine for two channels, left and right but for more channels I need to know precise channels layout (may be

golang using timeouts with channels

我怕爱的太早我们不能终老 提交于 2019-11-29 11:47:19
问题 I am using goroutines/channels to check if list of urls are reachable. Here is my code. This seems to always return true. Why is the timeout case not getting executed? The goal is to return false even if one of the urls is not reachable import "fmt" import "time" func check(u string) bool { time.Sleep(4 * time.Second) return true } func IsReachable(urls []string) bool { ch := make(chan bool, 1) for _, url := range urls { go func(u string) { select { case ch <- check(u): case <-time.After(time

How to detect if a user left a Phoenix channel due to a network disconnect?

╄→гoц情女王★ 提交于 2019-11-28 17:38:53
I have an Elixir/Phoenix server app and the clients connect through the build in channels system via websockets. Now I want to detect when an user leaves a channel. Sidenote: I'm using the javascript client library inside a Google Chrome Extension. For this I extracted the ES6 code from Phoenix, transpiled it to javascript, and tweaked it a little so it runs standalone. Now when I just close the popup, the server immediately triggers the terminate/2 function with reason = {:shutdown, :closed} . There is no kind of close-callback involved on the extension side, so this is great! But when the

Why using unbuffered channel in the same goroutine gives a deadlock

天大地大妈咪最大 提交于 2019-11-27 17:17:56
I'm sure that there is a simple explanation to this trivial situation, but I'm new to the go concurrency model. when I run this example package main import "fmt" func main() { c := make(chan int) c <- 1 fmt.Println(<-c) } I get this error : fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan send]: main.main() /home/tarrsalah/src/go/src/github.com/tarrsalah/tour.golang.org/65.go:8 +0x52 exit status 2 Why ? Wrapping c <- in a goroutine makes the example run as we expected package main import "fmt" func main() { c := make(chan int) go func(){ c <- 1 }() fmt.Println(<-c) } Again,

How to detect if a user left a Phoenix channel due to a network disconnect?

时光毁灭记忆、已成空白 提交于 2019-11-27 10:36:22
问题 I have an Elixir/Phoenix server app and the clients connect through the build in channels system via websockets. Now I want to detect when an user leaves a channel. Sidenote: I'm using the javascript client library inside a Google Chrome Extension. For this I extracted the ES6 code from Phoenix, transpiled it to javascript, and tweaked it a little so it runs standalone. Now when I just close the popup, the server immediately triggers the terminate/2 function with reason = {:shutdown, :closed}

Why does the use of an unbuffered channel in the same goroutine result in a deadlock?

感情迁移 提交于 2019-11-26 18:55:30
问题 I'm sure that there is a simple explanation to this trivial situation, but I'm new to the go concurrency model. when I run this example package main import "fmt" func main() { c := make(chan int) c <- 1 fmt.Println(<-c) } I get this error : fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan send]: main.main() /home/tarrsalah/src/go/src/github.com/tarrsalah/tour.golang.org/65.go:8 +0x52 exit status 2 Why ? Wrapping c <- in a goroutine makes the example run as we expected

How to stop a goroutine

眉间皱痕 提交于 2019-11-26 02:42:43
问题 I have a goroutine that calls a method, and passes returned value on a channel: ch := make(chan int, 100) go func(){ for { ch <- do_stuff() } }() How do I stop such a goroutine? 回答1: EDIT: I wrote this answer up in haste, before realizing that your question is about sending values to a chan inside a goroutine. The approach below can be used either with an additional chan as suggested above, or using the fact that the chan you have already is bi-directional, you can use just the one... If your