[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread Timothy Raymond
I'm not entirely sure, but my intuition says that using `time.After` like 
that with pending sends from another goroutine will cause that goroutine to 
leak. A better solution may be to use the `WithTimeout` functionality of 
the `context` package and then periodically check the `Done()` channel to 
see if the timeout has expired. It works something like this if you imagine 
`HeavyWork` is a call to an external API: 
https://play.golang.org/p/DRtgNBLnE5 .

On Sunday, August 6, 2017 at 3:53:36 AM UTC-4, Abhijit Desai wrote:
>
> Can you please help with below code to get output at specific cutoff time 
> and exit
>
> Thanks in advance
>
> Abhi
>
>
>
> package main
>
> import "time"
> import "fmt"
>
> func main() {
>
> c1 := make(chan string)
> 
> go func() { //Sending data after certain time
>   
> c1 <- "result 1"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 1 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 2 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 3 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 4 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 5 sec"
> }()
>
> select {
> case <-time.After(time.Second * 4): { //cut off 4s and return the 
> value
> res := <-c1
> fmt.Println(res)  // expecting result "result 2 afer 3 sec" 
> but returning "result 1"
> }
> }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Gert


On Monday, August 7, 2017 at 12:41:18 AM UTC+2, kortschak wrote:
>
> The reflect package is not mentioned in the spec (except once to 
> discuss struct tags), adding a built-in would require its definition 
> there, and complicate the language. Making it easier to use would also 
> have the disadvantage of increasing its use, packages with heavy 
> reflect use tend to be harder to reason about by virtue of having 
> reduced type constraints. 
>
> https://blog.golang.org/laws-of-reflection 
>
>
 I agree but so is cgo and disabling reflect by default i would not mind, 
but the fact is sometimes you have to use it. And when you need to use it 
you already drowning in complicated code to begin with, no need to make it 
even more complicated. Lets meet in the middle by only allowing reflect 
with a build flag.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [CGO] how to pass a 2d slice to C?

2017-08-06 Thread jianzhangbjz
Thanks your reply, I also used this way, but it still not work. code as the 
following.

gonameunits := []string{"gpu0", "gpu1", "gpu2", "gpu3"}
   nameunits := make([]*C.char, len(gonameunits))
   for i, _ := range gonameunits {
   nameunits[i] = C.CString(gonameunits[i])
   defer C.free(unsafe.Pointer(nameunits[i]))
   }
   fmt.Println("nameunits:", nameunits)

golevelmatrix := [][]int{{1}, {3, 3}, {3, 3, 2}}
   levelmatrix := make([][]C.int, len(golevelmatrix))
   for i, _ := range golevelmatrix {
   levelmatrix[i] = make([]C.int, len(golevelmatrix[i]))
   for j, _ := range golevelmatrix[i] {
   levelmatrix[i][j] = C.int(golevelmatrix[i][j])
   }
   }
   fmt.Println("levelmatrix:", levelmatrix)

C.test_settopologyresource(mod, C.CString("node1"), C.int(2), (**C.char
)(unsafe.Pointer([0])), (**C.int)(unsafe.Pointer([0][0
])))




在 2017年8月4日星期五 UTC+8下午8:09:34,Konstantin Khomoutov写道:
>
> On Fri, Aug 04, 2017 at 02:09:14AM -0700, jianzh...@gmail.com 
>  wrote: 
>
> > Hey Guys, 
> > 
> > I'm in trouble in the same issue. My code as the following: 
> > 
> > test.go 
> > ```go 
> > name := []string{"gpu0", "gpu1", "gpu2", "gpu3"} 
> > matrix := [3][3]int{{1, 0, 0}, {3, 3, 0}, {3, 3, 2}} 
> > 
> > C.test_settopologyresource(mod, C.CString("node1"), C.int(2), 
> > (**C.char)(unsafe.Pointer([0])), 
> > (**C.int)(unsafe.Pointer([0][0]))) 
> > ``` 
>
> I'm afraid that's not going to work: the elements of the "name" slice 
> are strings, and they can't be coersed to *C.char because a Go string is 
> internally a struct consisting of a pointer and a length. 
>
> So I think you'd need to make a "clone" data struct -- something like 
> this: 
>
>   cnames := make([]*C.Char, len(names)) 
>   for i, name := range names { 
> cnames[i] = C.CString(name) 
>   } 
>
> and then destroy those objects after returning from the C side: 
>
>   for _, p := range cnames { 
> C.free(p) 
>   } 
>
> [...] 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Dan Kortschak
>From the Laws of Reflection[1]:

> It's a powerful tool that should be used with care and avoided unless
> strictly necessary. 

The reflect package is not mentioned in the spec (except once to
discuss struct tags), adding a built-in would require its definition
there, and complicate the language. Making it easier to use would also
have the disadvantage of increasing its use, packages with heavy
reflect use tend to be harder to reason about by virtue of having
reduced type constraints.

[1]https://blog.golang.org/laws-of-reflection

On Sun, 2017-08-06 at 13:51 -0700, Gert wrote:
> Yes but its the way it's done that i think could be made more 
> straightforward, why not merge ValueOf and TypeOf in a build in 
> intermediate reflect type as in for example int(4) but then
> reflect(4)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Gert
Yes but its the way it's done that i think could be made more 
straightforward, why not merge ValueOf and TypeOf in a build in 
intermediate reflect type as in for example int(4) but then reflect(4)

On Sunday, August 6, 2017 at 5:57:40 PM UTC+2, Rich wrote:
>
> I don't understand... doesn't Reflect already do this?
> https://play.golang.org/p/CIm7aISztv
>
>
> On Saturday, August 5, 2017 at 12:58:52 PM UTC-4, Gert wrote:
>>
>> package main
>>
>> import (
>> "fmt"
>> "reflect"
>> )
>>
>> func main() {
>> x := 4
>> v1 := reflect.ValueOf(x)
>> fmt.Println("type:", v1.Type())
>> v2 := reflect.TypeOf(x)
>> fmt.Println("type:", v2)
>> }
>>
>> Kan we have something like this instead please
>>
>> package main
>>
>> import (
>> "fmt"
>> "reflect"
>> )
>>
>> func main() {
>> x := 4
>> r := reflect(x)
>> fmt.Println("type:", r.Type())
>> fmt.Println("value:", r.Value(int))
>> }
>>
>> Reflect should be a generic way of Go2, but everytime i need to reflect 
>> around a Go1 interface i want to go on a vacation...
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [Go2] Reflect

2017-08-06 Thread Rich
I don't understand... doesn't Reflect already do this?
https://play.golang.org/p/CIm7aISztv


On Saturday, August 5, 2017 at 12:58:52 PM UTC-4, Gert wrote:
>
> package main
>
> import (
> "fmt"
> "reflect"
> )
>
> func main() {
> x := 4
> v1 := reflect.ValueOf(x)
> fmt.Println("type:", v1.Type())
> v2 := reflect.TypeOf(x)
> fmt.Println("type:", v2)
> }
>
> Kan we have something like this instead please
>
> package main
>
> import (
> "fmt"
> "reflect"
> )
>
> func main() {
> x := 4
> r := reflect(x)
> fmt.Println("type:", r.Type())
> fmt.Println("value:", r.Value(int))
> }
>
> Reflect should be a generic way of Go2, but everytime i need to reflect 
> around a Go1 interface i want to go on a vacation...
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread desaiabhijit
yes this is what I want.. 

Need to access web service multiple times to get the entire data unless 
return status is not "completed" But same time I need timeout

Thanks for the help

Thanks

Abhi

On Sunday, August 6, 2017 at 7:48:05 PM UTC+5:30, snmed wrote:
>
> I still no get the idea behind your requirement, in your example you 
> calling the web service 6 times in sequential manner and then write it to 
> the channel.
> But again you can only write once to a channel with a capacity of one, as 
> long as you not read from the same channel and you still read it in the 
> select statement.
> That means all other calls to 'GetPartWebServiceData()' in the goroutine 
> are blocked until that read in the select statement happens. In your case 
> it is always the first
> value written to the channel.
>
> I try to give you a solution with although i'm not completely understand 
> your requirements:
>
> Here a working sequential solution: https://play.golang.org/p/2qohwIjP96
>
> I hope that helps
>
> Cheers snmed
>
> Am Sonntag, 6. August 2017 13:05:11 UTC+2 schrieb Abhijit Desai:
>>
>> Requirement is to collect the data with in cuttoff time say 3 sec by 
>> invoking web service multiple times and return only latest invoked data
>>
>> c1 <- "result 1" // In real scenario this taking almost 1 seconds as in 
>> real scenario it's taking Part chunk of data from Web Service
>>
>> Something like... Expecting data from c1 <- 
>> GetPartWebServiceData("request 3") //at least I should get this data!?
>>
>>
>> package main
>>
>> import "time"
>> import "fmt"
>>
>> func main() {
>>
>> c1 := make(chan string, 1)
>> 
>> go func() {
>>   
>> c1 <- GetPartWebServiceData("request 1") //say try 6 times
>> c1 <- GetPartWebServiceData("request 2")
>> c1 <- GetPartWebServiceData("request 3") //at least I should get 
>> this data!?
>> c1 <- GetPartWebServiceData("request 4")
>> c1 <- GetPartWebServiceData("request 5")
>> c1 <- GetPartWebServiceData("request 6")
>> }()
>>
>> select {
>> case res := <-c1: //here program get out without waiting 3 
>> seconds because it got the data
>> fmt.Println(res)
>> case <-time.After(time.Second * 4):
>> fmt.Println("timeout")
>> }
>> }
>>
>> func GetPartWebServiceData(request string) string{
>> time.Sleep(time.Second * 1) // Time Consuming work returning part 
>> value
>> partResponse := "Response for " + request  //some response
>> return partResponse
>> }
>>
>>
>>
>> On Sunday, August 6, 2017 at 4:03:08 PM UTC+5:30, snmed wrote:
>>>
>>> Hi 
>>>
>>> What are you trying to solve? Your channel has a capacity of 1, the 
>>> first write to c1 is successful but the second write to c1 is blocked until 
>>> it has been read in the select statement. And therefore you print the first 
>>> value written to c1.
>>>
>>> I recommend you to read this 
>>> https://golang.org/doc/effective_go.html#channels documentation about 
>>> channels.
>>>
>>> Cheers snmed
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread snmed
I still no get the idea behind your requirement, in your example you 
calling the web service 6 times in sequential manner and then write it to 
the channel.
But again you can only write once to a channel with a capacity of one, as 
long as you not read from the same channel and you still read it in the 
select statement.
That means all other calls to 'GetPartWebServiceData()' in the goroutine 
are blocked until that read in the select statement happens. In your case 
it is always the first
value written to the channel.

I try to give you a solution with although i'm not completely understand 
your requirements:

Here a working sequential solution: https://play.golang.org/p/2qohwIjP96

I hope that helps

Cheers snmed

Am Sonntag, 6. August 2017 13:05:11 UTC+2 schrieb Abhijit Desai:
>
> Requirement is to collect the data with in cuttoff time say 3 sec by 
> invoking web service multiple times and return only latest invoked data
>
> c1 <- "result 1" // In real scenario this taking almost 1 seconds as in 
> real scenario it's taking Part chunk of data from Web Service
>
> Something like... Expecting data from c1 <- GetPartWebServiceData("request 
> 3") //at least I should get this data!?
>
>
> package main
>
> import "time"
> import "fmt"
>
> func main() {
>
> c1 := make(chan string, 1)
> 
> go func() {
>   
> c1 <- GetPartWebServiceData("request 1") //say try 6 times
> c1 <- GetPartWebServiceData("request 2")
> c1 <- GetPartWebServiceData("request 3") //at least I should get 
> this data!?
> c1 <- GetPartWebServiceData("request 4")
> c1 <- GetPartWebServiceData("request 5")
> c1 <- GetPartWebServiceData("request 6")
> }()
>
> select {
> case res := <-c1: //here program get out without waiting 3 
> seconds because it got the data
> fmt.Println(res)
> case <-time.After(time.Second * 4):
> fmt.Println("timeout")
> }
> }
>
> func GetPartWebServiceData(request string) string{
> time.Sleep(time.Second * 1) // Time Consuming work returning part value
> partResponse := "Response for " + request  //some response
> return partResponse
> }
>
>
>
> On Sunday, August 6, 2017 at 4:03:08 PM UTC+5:30, snmed wrote:
>>
>> Hi 
>>
>> What are you trying to solve? Your channel has a capacity of 1, the first 
>> write to c1 is successful but the second write to c1 is blocked until it 
>> has been read in the select statement. And therefore you print the first 
>> value written to c1.
>>
>> I recommend you to read this 
>> https://golang.org/doc/effective_go.html#channels documentation about 
>> channels.
>>
>> Cheers snmed
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Tell "dep" to ignore a dependency?

2017-08-06 Thread Miki Tebeka
Wasn't aware this is possible, will do - thanks.

On Sunday, August 6, 2017 at 4:53:13 PM UTC+3, Paul Tötterman wrote:
>
> Thanks. But if I'll use constraint I'll need to rewrite all the import 
>> paths in my code (and maybe in the vendor directory as well)
>>
>
> Maybe I've misunderstood something, but I was expecting you wouldn't have 
> to:
>
> [[constraint]]
> name = "github.com/original/library"
> source = "github.com/your/fork"
>
> Cheers,
> Paul 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread desaiabhijit
hi Bjoern

>>> Why would you expect this? "result 1" is the fist value that was sent 
to the channel. Channels are sort of FIFO.

Yeah I know.. but what is the workaround to get latest c1 value which is 
retrieve just before timeout

Do I need to use "for ( loop )" around Select till timeout to invoke res: = 

>
>
> Am Sonntag, 6. August 2017 09:53:36 UTC+2 schrieb Abhijit Desai:
>>
>> Can you please help with below code to get output at specific cutoff time 
>> and exit
>>
>> Thanks in advance
>>
>> Abhi
>>
>>
>>
>> package main
>>
>> import "time"
>> import "fmt"
>>
>> func main() {
>>
>> c1 := make(chan string)
>> 
>> go func() { //Sending data after certain time
>>   
>> c1 <- "result 1"
>>
>> time.Sleep(time.Second * 1)
>> c1 <- "result 2 afer 1 sec"
>>
>> time.Sleep(time.Second * 1)
>> c1 <- "result 2 afer 2 sec"
>>
>> time.Sleep(time.Second * 1)
>> c1 <- "result 2 afer 3 sec"
>>
>> time.Sleep(time.Second * 1)
>> c1 <- "result 2 afer 4 sec"
>>
>> time.Sleep(time.Second * 1)
>> c1 <- "result 2 afer 5 sec"
>> }()
>>
>> select {
>> case <-time.After(time.Second * 4): { //cut off 4s and return the 
>> value
>> res := <-c1
>> fmt.Println(res)  // expecting result "result 2 afer 3 sec" 
>> but returning "result 1"
>>
>
> Why would you expect this? "result 1" is the fist value that was sent to 
> the channel. Channels are sort of FIFO.
>  
>
>> }
>> }
>> }
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Tell "dep" to ignore a dependency?

2017-08-06 Thread paul . totterman

>
> Thanks. But if I'll use constraint I'll need to rewrite all the import 
> paths in my code (and maybe in the vendor directory as well)
>

Maybe I've misunderstood something, but I was expecting you wouldn't have 
to:

[[constraint]]
name = "github.com/original/library"
source = "github.com/your/fork"

Cheers,
Paul 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Tell "dep" to ignore a dependency?

2017-08-06 Thread paul . totterman
Hi,

I plan to use "dep" and also to place "vendor" in the git repository. 
> However I have one dependency in vendor which is locally patched. The 
> problem for me is that "dep ensure" overwrites my patch every time. Is 
> there a way to tell "dep" to ignore this specific package? (There are 
> overrides, from what what I've seen you can just set a specific version 
> there).
>

You should be able to use a [[constraint]] -section in Gopkg.toml to point 
the source of a package to your own forked repository.

Cheers,
Paul 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread bjoern.pirnay via golang-nuts


Am Sonntag, 6. August 2017 09:53:36 UTC+2 schrieb Abhijit Desai:
>
> Can you please help with below code to get output at specific cutoff time 
> and exit
>
> Thanks in advance
>
> Abhi
>
>
>
> package main
>
> import "time"
> import "fmt"
>
> func main() {
>
> c1 := make(chan string)
> 
> go func() { //Sending data after certain time
>   
> c1 <- "result 1"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 1 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 2 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 3 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 4 sec"
>
> time.Sleep(time.Second * 1)
> c1 <- "result 2 afer 5 sec"
> }()
>
> select {
> case <-time.After(time.Second * 4): { //cut off 4s and return the 
> value
> res := <-c1
> fmt.Println(res)  // expecting result "result 2 afer 3 sec" 
> but returning "result 1"
>

Why would you expect this? "result 1" is the fist value that was sent to 
the channel. Channels are sort of FIFO.
 

> }
> }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-06 Thread Dorival Pedroso
Fixed. Cheers.

On Sunday, August 6, 2017 at 12:23:57 PM UTC+10, Michael Jones wrote:
>
> Great. Hope it helps. I had a typo in power 0 (which is never called. 
> Change the return to 1.0.
>
> On Sat, Aug 5, 2017 at 6:50 PM  wrote:
>
>> Thanks, Michael.
>>
>> I've created a tiny project with those files here: 
>> https://github.com/cpmech/go-fast-math-experiments
>>
>> The output of go test -run=XXX -bench=. -benchtime=10s (in the xmath 
>> package) is:
>> BenchmarkPowStd-32   349.8 ns/op
>> BenchmarkPowP-32 20 8.85 ns/op
>> BenchmarkPowFI-32 20 6.31 ns/op
>> BenchmarkPowStd10-32 1   237 ns/op
>> BenchmarkPowP10-32   539.1 ns/op
>> BenchmarkPowFI10-32   344.6 ns/op
>> BenchmarkPowStd20-32 3000   549 ns/op
>> BenchmarkPowP20-32   297.4 ns/op
>> BenchmarkPowFI20-32   293.8 ns/op
>> BenchmarkPowStd50-32 1000  1584 ns/op
>> BenchmarkPowP50-32   5000   304 ns/op
>> BenchmarkPowFI50-32   5000   249 ns/op
>> BenchmarkPowStd100-32 500  3529 ns/op
>> BenchmarkPowP100-32   2000   692 ns/op
>> BenchmarkPowFI100-32 3000   522 ns/op
>> BenchmarkPowStd200-32 200  9221 ns/op
>> BenchmarkPowP200-32   1000  1623 ns/op
>> BenchmarkPowFI200-32 2000  1124 ns/op
>>
>> Your table-based function (PowFI) wins overall with ~7x speedup vs mine 
>> (PowP) with ~5x speedup (compared to the std math which is 
>> non-integer-specific, so, not very fair... but OK as reference).
>>
>> Cheers.
>> Dorival
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
> -- 
> Michael T. Jones
> michae...@gmail.com 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Concurrency Testimonial

2017-08-06 Thread Dorival Pedroso
Great news. Thanks for sharing

On Sunday, August 6, 2017 at 1:37:11 AM UTC+10, Mandolyte wrote:
>
> This past week I wrote an "audit" program for management to see how a long 
> running data migration effort was going (it will take several months to 
> complete). I was little discouraged when I found that the audit was on pace 
> to complete in 10 days. That got me to thinking of making a concurrent 
> version of the code. It's been over a year since I last did anything with 
> channels, so I spent some time studying my previous examples, did some 
> google searches, etc.
>
> In just a few hours I had it converted, only had a single deadlock bug to 
> figure out. Found that it was very easy to reason about. I made it so it 
> could use an argument specified number of go routines. With 10 concurrent 
> go routines, it is on pace to complete in less than 32 hours.
>
> So just a big thank you for such a nice language!
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Goroutines chan to get data at specific time

2017-08-06 Thread desaiabhijit
Requirement is to collect the data with in cuttoff time say 3 sec by 
invoking web service multiple times and return only latest invoked data

c1 <- "result 1" // In real scenario this taking almost 1 seconds as in 
real scenario it's taking Part chunk of data from Web Service

Something like... Expecting data from c1 <- GetPartWebServiceData("request 
3") //at least I should get this data!?


package main

import "time"
import "fmt"

func main() {

c1 := make(chan string, 1)

go func() {
  
c1 <- GetPartWebServiceData("request 1") //say try 6 times
c1 <- GetPartWebServiceData("request 2")
c1 <- GetPartWebServiceData("request 3") //at least I should get 
this data!?
c1 <- GetPartWebServiceData("request 4")
c1 <- GetPartWebServiceData("request 5")
c1 <- GetPartWebServiceData("request 6")
}()

select {
case res := <-c1: //here program get out without waiting 3 
seconds because it got the data
fmt.Println(res)
case <-time.After(time.Second * 4):
fmt.Println("timeout")
}
}

func GetPartWebServiceData(request string) string{
time.Sleep(time.Second * 1) // Time Consuming work returning part value
partResponse := "Response for " + request  //some response
return partResponse
}



On Sunday, August 6, 2017 at 4:03:08 PM UTC+5:30, snmed wrote:
>
> Hi 
>
> What are you trying to solve? Your channel has a capacity of 1, the first 
> write to c1 is successful but the second write to c1 is blocked until it 
> has been read in the select statement. And therefore you print the first 
> value written to c1.
>
> I recommend you to read this 
> https://golang.org/doc/effective_go.html#channels documentation about 
> channels.
>
> Cheers snmed
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Generics are overrated.

2017-08-06 Thread Lucio
Got it. In the same document:

"Halfway the functional design of the X1, I guess early 1957, Bram and 
Carel confronted me with the idea of the interrupt, and I remember that I 
panicked, being used to machines with reproducible behaviour. How was I 
going to identify a bug if I had introduced one? After I had delayed the 
decision to include the interrupt for 3 months, Bram and Carel flattered me 
out of my resistance, it was decided that an interrupt would be included 
and I began to study the problem. To start with I tried to convince myself 
that it was possible to save and restore enough of the machine state so 
that, after the servicing of the interrupt, under all circumstances the 
interrupted computation could be resumed correctly."

Thank you again, Peter.

Lucio.


On Sunday, 6 August 2017 12:03:07 UTC+2, Lucio wrote:
>
> Thank you, Peter.
>
> Maybe someone else can corroborate my impression that Dijkstra did not 
> immediately accept the idea of interrupts and felt it would make 
> programming too difficult?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Goroutines chan to get data at specific time

2017-08-06 Thread snmed
Hi 

What are you trying to solve? Your channel has a capacity of 1, the first write 
to c1 is successful but the second write to c1 is blocked until it has been 
read in the select statement. And therefore you print the first value written 
to c1.

I recommend you to read this https://golang.org/doc/effective_go.html#channels 
documentation about channels.

Cheers snmed

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Generics are overrated.

2017-08-06 Thread Lucio
Thank you, Peter.

Maybe someone else can corroborate my impression that Dijkstra did not 
immediately accept the idea of interrupts and felt it would make 
programming too difficult?

Lucio.

On Saturday, 5 August 2017 19:44:26 UTC+2, peterGo wrote:
>
> Lucio,
>
> "It took Dijkstra quite some effort to accept the concept of "interrupts" 
> (quotation anyone?), but eventually he went with it."
>
> E.W. Dijkstra Archive: My recollections of operating system design 
> (EWD1303)
>
> https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/EWD1303.html
>
> "The third arrangement, known as "the interrupt", circumvents all these 
> dilemmas. While the computer calculates at full speed, a piece of dedicated 
> hardware monitors the outside world for completion signals from 
> communication devices. When a completion is detected, the program under 
> execution is interrupted after the current instruction and in such a 
> fashion that it can be resumed at a later moment as if nothing had 
> happened, thus instantaneously freeing the central processor for a suddenly 
> more urgent task. After the interrupt the processor would execute a 
> standard program establishing the source of the interruption and taking 
> appropriate action."
>
> Peter
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Tell "dep" to ignore a dependency?

2017-08-06 Thread Miki Tebeka
Hi,

I plan to use "dep" and also to place "vendor" in the git repository. 
However I have one dependency in vendor which is locally patched. The 
problem for me is that "dep ensure" overwrites my patch every time. Is 
there a way to tell "dep" to ignore this specific package? (There are 
overrides, from what what I've seen you can just set a specific version 
there).

Thanks,
--
Miki

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Goroutines chan to get data at specific time

2017-08-06 Thread desaiabhijit
Can you please help with below code to get output at specific cutoff time 
and exit

Thanks in advance

Abhi



package main

import "time"
import "fmt"

func main() {

c1 := make(chan string)

go func() { //Sending data after certain time
  
c1 <- "result 1"

time.Sleep(time.Second * 1)
c1 <- "result 2 afer 1 sec"

time.Sleep(time.Second * 1)
c1 <- "result 2 afer 2 sec"

time.Sleep(time.Second * 1)
c1 <- "result 2 afer 3 sec"

time.Sleep(time.Second * 1)
c1 <- "result 2 afer 4 sec"

time.Sleep(time.Second * 1)
c1 <- "result 2 afer 5 sec"
}()

select {
case <-time.After(time.Second * 4): { //cut off 4s and return the 
value
res := <-c1
fmt.Println(res)  // expecting result "result 2 afer 3 sec" but 
returning "result 1"
}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.