This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type IntContainer []int | |
| func (i IntContainer) Iterator(cancel <-chan struct{}) <-chan int { | |
| ch := make(chan int) | |
| go func() { | |
| for _, val := range i { | |
| select { | |
| case ch <- val: | |
| case <-cancel: | |
| close(ch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type IntContainer []int | |
| func (i IntContainer) Iterator() <-chan int { | |
| ch := make(chan int) | |
| go func() { | |
| for _, val := range i { | |
| ch <- val | |
| } | |
| close(ch) | |
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| intMap := make(map[string]int) | |
| // Valid | |
| value, ok := intMap["foo"] | |
| println(value, ok) | |
| // Also valid | |
| value := intMap["foo"] | |
| println(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| go test -race github.com/gdamore/mangos/test | |
| --- FAIL: TestBusTLS (1.00s) | |
| common_test.go:500: Address tls+tcp://127.0.0.1:43934, 5 Cases | |
| common_test.go:149: Jan 14 19:17:27.210: Id 0: Got dup START from 1 | |
| common_test.go:149: Jan 14 19:17:27.382: Id 0: Got dup START from 1 | |
| common_test.go:149: Jan 14 19:17:27.382: Id 0: Got dup START from 2 | |
| common_test.go:149: Jan 14 19:17:27.473: Id 0: Sent all 7 messages | |
| common_test.go:149: Jan 14 19:17:27.477: Id 4: Got all 7 messages | |
| common_test.go:149: Jan 14 19:17:27.477: Id 3: Got all 7 messages | |
| common_test.go:149: Jan 14 19:17:27.478: Id 2: Got all 7 messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| survey, _ = surveyor.NewSocket() | |
| survey.AddTransport(tcp.NewTransport()) | |
| survey.Listen("tcp://:8000") | |
| survey.SetOption(mangos.OptionSurveyTime, time.Second) | |
| for { | |
| survey.Send("Is anybody out there?") | |
| for { | |
| if msg, err = survey.Recv(); err != nil { | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "time" | |
| "github.com/gdamore/mangos" | |
| "github.com/gdamore/mangos/protocol/pub" | |
| "github.com/gdamore/mangos/protocol/sub" | |
| "github.com/gdamore/mangos/transport/ipc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public <T> T createFromCursor(Cursor cursor, Class<T> modelClass) throws ModelConfigurationException, InfinitumRuntimeException { | |
| return createFromCursorRec(cursor, modelClass); | |
| } | |
| @SuppressWarnings("unchecked") | |
| private <T> T createFromCursorRec(Cursor cursor, Class<T> modelClass) throws ModelConfigurationException, InfinitumRuntimeException { | |
| SqliteResult result = new SqliteResult(cursor); | |
| T ret = (T) mClassReflector.getClassInstance(modelClass); | |
| List<Field> fields = mPersistencePolicy.getPersistentFields(modelClass); | |
| for (Field field : fields) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bill.getDepartment().setName("Bill's Department"); | |
| String dept = frank.getDepartment().getName(); // Should yield "Bill's Department" but doesn't |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int computeModelHash(Class<?> c, Serializable pk) { | |
| final int PRIME = 31; | |
| int hash = 7; | |
| hash *= PRIME + c.hashCode(); | |
| hash *= PRIME + pk.hashCode(); | |
| return hash; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Map<Integer, Object> entities = new HashMap<Integer, Object>(); |