Interesting stuff! Thanks for the pointer on https://github.com/mh-cbon/mutexer <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fmh-cbon%2Fmutexer&sa=D&sntz=1&usg=AFQjCNGx6jkyGN5ft0dHpV_znYMkCSi5KQ>, missed that! I have noticed that the https://github.com/mh-cbon/mutexer <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fmh-cbon%2Fmutexer&sa=D&sntz=1&usg=AFQjCNGx6jkyGN5ft0dHpV_znYMkCSi5KQ> version doesnt implement all the methods the lister does (such as map, filter).
I was thinking of doing something similar myself for iterator types e.g. Next(), Rewind() etc. Might have a play with a fork of Lister and see if I can get a version working. Incidentally, out of curiosity, I noticed that the output code is "hard coded" into the main.go; would it not be clearer/more maintainable to use templates? On Wednesday, May 3, 2017 at 4:37:42 PM UTC+1, mhh...@gmail.com wrote: > > hi > > > Can anyone else recommend any other generators that produce > lists/iterators like this? > > good Q. > > > Is the resulting generated code safe to use from multiple go routines? > > The slice itself nop, because, for that you want to use > > https://github.com/mh-cbon/channeler > or > https://github.com/mh-cbon/mutexer > > You make a typed slice then you facade it with one of the syncer. > > So yep, that example is not TS, > this was just for fun and demo > > backend := NewTomates() // This is not TS, it d need an additional > layer > backend.Push(Tomate{Name: "red"}) > jsoner := NewJSONTomates(backend) > httper := NewHTTPTomates(jsoner) > > // public views > http.HandleFunc("/", httper.At) > > /* > curl -H "Accept: application/json" -H "Content-type: > application/json" -X POST -d ' {"i":0}' http://localhost:8080/ > */ > > log.Fatal(http.ListenAndServe(":8080", nil)) > > > In the same manner if you have n collections in memory which needs TS, > that d be inappropriate to have n TS lists communicating with each other > on the main routine, > that d create additional contentions, > you d better create a controller, that is totally TS, > that access those slice without syncing. > > > On Wednesday, May 3, 2017 at 4:30:20 PM UTC+2, Ben Davies wrote: >> >> Is the resulting generated code safe to use from multiple go routines? >> >> On Saturday, April 29, 2017 at 4:06:27 PM UTC+1, mhh...@gmail.com wrote: >>> >>> Hi, >>> >>> several generators i made to avoid some duplication. >>> >>> https://github.com/mh-cbon/lister >>> >>> Package lister is a generator to generate typed slice. >>> >>> >>> https://github.com/mh-cbon/channeler >>> >>> Package channeler is a cli generator to generate channeled version of a >>> type. >>> >>> https://github.com/mh-cbon/mutexer >>> >>> Package mutexer is a cli generator to generate mutexed version of a type. >>> >>> >>> so basically, using below code you got hundreds of line generated for >>> you, >>> >>> >>> in that example to make a mutexed []Tomate. >>> >>> >>> But as it s not too stupid, or tries too, it will be able to handle >>> >>> pointer and basic types >>> >>> mutexed []*Tomate >>> >>> mutexed []string >>> >>> ect >>> >>> >>> It should also be able to lookup for a constructor of the src type >>> (Tomate), >>> >>> and reproduce it into the dest type implementation. >>> >>> >>> There is both mutexer / channeler because both cases applies for reasons. >>> >>> >>> The lister is a convenient way to create typed slice. >>> >>> >>> package demo >>> >>> // Tomate is about red vegetables to make famous italian food. >>> type Tomate struct { >>> Name string >>> } >>> >>> // GetID return the ID of the Tomate. >>> func (t Tomate) GetID() string { >>> return t.Name >>> } >>> >>> //go:generate lister vegetables_gen.go Tomate:Tomates >>> //go:generate mutexer vegetuxed_gen.go Tomates:Tomatex >>> >>> hth >>> >>> -- 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.