All Projects → sadlil → Go Trigger

sadlil / Go Trigger

Licence: mit
A Global event triggerer for golang. Defines functions as event with id string. Trigger the event anywhere from your project.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Go Trigger

Postgresql2websocket
Send PostgreSQL notifications over websockets
Stars: ✭ 58 (-72.64%)
Mutual labels:  trigger
Squirrel
squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
Stars: ✭ 1,789 (+743.87%)
Mutual labels:  event-handlers
Node Webhooks
↪️ Node.js module to create and trigger your own webHooks.
Stars: ✭ 157 (-25.94%)
Mutual labels:  trigger
Observable
minimalist event system for Python
Stars: ✭ 66 (-68.87%)
Mutual labels:  event-handlers
Fluentmediator
🔀 FluentMediator is an unobtrusive library that allows developers to build custom pipelines for Commands, Queries and Events.
Stars: ✭ 128 (-39.62%)
Mutual labels:  event-handlers
Keel
Kubernetes Operator to automate Helm, DaemonSet, StatefulSet & Deployment updates
Stars: ✭ 1,870 (+782.08%)
Mutual labels:  trigger
Hyper Match
HyperTerm extension which matches regular expressions with predefined commands
Stars: ✭ 15 (-92.92%)
Mutual labels:  trigger
Hooka
😎 A webhook server with zero coding
Stars: ✭ 180 (-15.09%)
Mutual labels:  trigger
3factor
3factor app is an architecture pattern for modern fullstack apps. 3factor apps are fast to build and are highly scalable.
Stars: ✭ 130 (-38.68%)
Mutual labels:  event-handlers
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (-33.49%)
Mutual labels:  event-handlers
Tail
[Revamped] Go package for reading from continuously updated files (tail -f)
Stars: ✭ 81 (-61.79%)
Mutual labels:  trigger
Plsh
PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.
Stars: ✭ 111 (-47.64%)
Mutual labels:  trigger
Hierarchy Data Closure Table
This is a mysql and postgresql store procedure and trigger implementation of closure table in RDBMS about hierarchy data model.
Stars: ✭ 135 (-36.32%)
Mutual labels:  trigger
Ws Wrapper
Lightweight WebSocket lib with socket.io-like event handling, requests, and channels
Stars: ✭ 58 (-72.64%)
Mutual labels:  event-handlers
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (-16.04%)
Mutual labels:  event-handlers
Aura.signal
SignalSlots / EventHandler Implementation
Stars: ✭ 32 (-84.91%)
Mutual labels:  event-handlers
Dropwizard Jobs
Scheduling / Quartz integration for Dropwizard
Stars: ✭ 132 (-37.74%)
Mutual labels:  trigger
Easybutton
Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
Stars: ✭ 187 (-11.79%)
Mutual labels:  trigger
Cqrs
cqrs framework in go
Stars: ✭ 179 (-15.57%)
Mutual labels:  event-handlers
Quartz Manager
UI Manager for Quartz Scheduler. Scheduler console and job monitor (Rest API + angular frontend)
Stars: ✭ 140 (-33.96%)
Mutual labels:  trigger

go-trigger

Go Trigger is a global event trigger for golang. Define an event with a task specified to that event and Trigger it from anywhere you want.

Get The Package

$ go get -u github.com/sadlil/go-trigger

How to switch to a specific version

go get the package. Go to the package directory in your $GOPATH/src. Change the tag using git. go install the package.

$ go get -u github.com/sadlil/go-trigger
$ cd $GOPATH/src/github.com/sadlil/go-trigger
$ git checkout tags/<tag_name>
$ go install

Currently available Tags

  • v0.01
    • Global event with unique key Id.
    • Trigger Event,
    • List Events,
    • Clear and Delete Events,
    • Trigger event in background,
    • Local Event,
    • Thread Safe Mutex Lock.

How To Use

1. Global Events

Import the package into your code. Add events with trigger.On method. And call that event handler with trigger.Fire method. All the events added like this will be global events. You can call Fire from anywhere.

package main

import (
  "github.com/sadlil/go-trigger"
  "fmt"
)


func main() {
  trigger.On("first-event", func() {
    // Do Some Task Here.
    fmt.Println("Done")
  })
  trigger.Fire("first-event")
}

You can define your events from another package

  trigger.On("second-event", packagename.FunctionName)
  trigger.Fire("second-event")

You can define events with parameteres and return types.

func TestFunc(a, b int) int {
    return a + b
}

// Call them using
trigger.On("third-event", TestFunc)
values, err := trigger.Fire("third-event", 5, 6)

// IMPORTANT : You need to type convert Your Returned Values using
// values[0].Int()

You can define your event in one package and trigger it another package. Your event and trigger are global. Define anywhere, fire anywhere. You can define any function in any package as event you only need to import the function's specified package where you define the event. Where you trigger the event, you do not need to import it there.

//---------------------------------------------
  package a
  
  func AFunction(one, two int) int {
    return one + two
  }
  
  
//---------------------------------------------
  package b
  import (
    "yourdirectory/a"
    "github.com/sadlil/go-trigger"
  )
  
  func() {
    trigger.On("new-event", a.AFunction)
  }
  
  
//---------------------------------------------
  package c
  import (
    "github.com/sadlil/go-trigger"
  )
  
  func() {
    values, err := trigger.Fire("new-event", 10, 10) 
    // You don't need to import package a here.
    fmt.Println(values[0].Int())
  }

You can run events in background with FireBackground()

func main() {
  trigger.On("first-event", func() {
    for i := 1; i <= 1000; i++ {
      fmt.Println(i)
    }
  })
  channel, err := trigger.FireBackground("first-event")
  fmt.Println("Event runs")
  //read the returned channel
  values := <- channel
  
  trigger.FireBackground("first-event")
  fmt.Println("Running 2nd Event")
}

2. Local Events

Trigger instance that will not effecct the global event. All event added to an local event instace can call only via this trigger instance. This is implementation of plugable Trigger interface.

Create a local trigger instance,

package main

import (
  "github.com/sadlil/go-trigger"
  "fmt"
)


func main() {
  t := trigger.New()
  t.On("first-event", func() {
    // Do Some Task Here.
    fmt.Println("Done")
  })
  t.Fire("first-event")
  
  // t2 is another trigger instance that will be separate from t1.
  t2 := trigger.New()
  t2.On("first-event", func() {
    // Do Some Task Here.
    fmt.Println("Done")
  })
  t2.Fire("first-event")
}

All other methods are availabe on any local trigger instance

Available methods

On(event string, task interface{}) error
  - Add a Event. task must be function. Throws an error if the event is duplicated.
   
Fire(event string, params ...interface{}) ([]reflect.Value, error)
  - Fires the task specified with the event key. params are the parameter and
  [] is the returned values of task. Fire Triggers the event and wait for it to
  end until it goes to execute the following codes.
  
FireBackground(event string, params ...interface{}) (chan []reflect.Value, error)
  - Fires the task specified with the event key. Unlike Fire it runs the event in
  background in go routine. It triggers the event but does not wait for the event
  to end. It writes the returned values of the event in a channel and returns the
  channel of reflect.Values. You can get the returned values by reading the
  channel (IE. ret := <- returned channel).
  
  - As FireBackground does not wait for the event to end first, if your program 
  exits it will stop any running event that did not finishes. So make sure your
  background events exits before ending the program.   


Clear(event string) error
  - Delete a event from the event list. throws an error if event not found.
  
ClearEvents()
  - Deletes all event from the event list.
  
HasEvent(event string) bool
  - Checks if a event exists or not. Return true if the event list have a event with 
  that key.  false otherwise.
  
Events() []string
  - Returns all the events added.
  
EventCount() int
  - Returns count of the events. If none found return 0;
  

Under Development Features

  1. Multiple event handler for a event.

Licence

Licenced under MIT Licence
Any Suggestions and Bug Report will be gladly appreciated.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].