Created
May 17, 2012 20:46
-
-
Save jordanorelli/2721495 to your computer and use it in GitHub Desktop.
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
| paramlist := map[string]params{ | |
| "one": ¶ms{ ... }, | |
| "two": ¶ms{ ... }, | |
| "three": ¶ms{ ... }, | |
| } | |
| results := make(map[string]result, len(paramlist)) | |
| for k, v := range paramlist { | |
| wg.Add() | |
| go func(label string, myparams param) { | |
| defer wg.Done() | |
| // something that causes a result to be created | |
| results[label] = result | |
| }(k, v) | |
| } | |
| wg.Wait() | |
| // at this point, results is a complete map[string]result |
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
| c := make(chan resultEnvelope) | |
| paramlist := map[string]params{ | |
| "one": ¶ms{ ... }, | |
| "two": ¶ms{ ... }, | |
| "three": ¶ms{ ... }, | |
| } | |
| for k, v := range paramlist { | |
| go func(label string, myparams param) { | |
| // something that causes a result to be created | |
| c <- resultEnvelope{Key: label, Value: result} | |
| }(k, v) | |
| } | |
| results := make(map[string]result, len(paramlist)) | |
| for _, envelope := range c { | |
| results[envelope.Key] = envelope.Value | |
| if received == len(paramlist) { | |
| break | |
| } | |
| } | |
| // at this point, results is a complete map[string]result. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment