Is there a golang lib abstracting goroutines to a simpler concept?

I know goroutines are like the holy grail in concurrency, smp etc but:
What is if I something in a single threaded way like node.js:
https://strongloop.com/strongblog/node-js-event-loop/
or ObjC:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

Or do I always need to use custom stuff like this:


If i want to code event driven like guis?

I find it hard to understand what you want to do. Make sure that no more than single gooutine is executing at the same time? Fire events asynchronously and make sure they’re processed in order, one by one?

2 Likes

Fire events asynchronously and make sure they’re processed in order

Then create a “event processing” goroutine that read events off the channel.

something like

func processEvents(eventQueue chan func(), done chan struct{}) {
   for {
      select {
      case event := <-eventQueue:
         event()
      case <-done:
         return
      }
   }
}
2 Likes

Thanks for the help! I will try it out

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.