Skip to content
/ golib Public

Library of useful services, tools, and structures written for Go

License

Notifications You must be signed in to change notification settings

jpxor/golib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jpxor Golib

Library of useful services, tools, and structures written for Go.

  • mutmux
  • pubsub

Mutmux

Mutex Multiplexer for synchronized concurrent accesses to a set of shared resources. The original use case was to handle many go routines performing io operations on a set of many files in undeterministic fashion.

use

// create Mutmux
var mmux = mutmux.Init()

// get lock before using shared resource
lock := mmux.GetLock(filename)

// exclusive access to resource
useResource(filename)

// release the lock when you are done
lock.Release()

Pubsub

Publish-Subscribe messaging service.

use

// Create the pubsub instance
ps := pubsub.Init(4)

// Subscribe to named channel (topic), 
// Provides a receiving chan and an id
// for unsubscribing later.
recv, rid := ps.Subscribe("demo")

// Publish any message
ps.Publish("demo", "Hello PubSub!")
ps.Publish("demo", &ArbitraryStruct)

// Recieve messages like you would
// with any Go chan
for {
   val := <-recv
   if val == nil {
      fmt.Printf("reciever was closed\n")
      break
   }
   msgPtr := val.(*Message)
   fmt.Printf("%s\n", msgPtr)
}

// Unsubscribe using receiver id
ps.Unsubscribe("demo", rid)

About

Library of useful services, tools, and structures written for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages