本文整理匯總了Golang中github.com/influx6/flux.Reactive函數的典型用法代碼示例。如果您正苦於以下問題:Golang Reactive函數的具體用法?Golang Reactive怎麽用?Golang Reactive使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Reactive函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BinaryLauncher
// BinaryLauncher returns a new Task generator that builds a binary runner from the given properties, which causing a relaunch of a binary file everytime it recieves a signal, it sends out a signal onces its done running all commands
func BinaryLauncher(bin string, args []string) flux.Reactor {
var channel chan bool
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if channel == nil {
channel = RunBin(bin, args, func() {
root.Reply(true)
}, func() {
go root.Close()
})
}
select {
case <-root.CloseNotify():
close(channel)
return
case <-time.After(0):
//force check of boolean values to ensure we can use correct signal
if cmd, ok := data.(bool); ok {
channel <- cmd
return
}
//TODO: should we fallback to sending true if we receive a signal normally? or remove this
// channel <- true
}
}))
}
示例2: ChunkFileScanAdaptor
// ChunkFileScanAdaptor provides a Stacks for parser.Parser
func ChunkFileScanAdaptor() flux.Reactor {
return flux.Reactive(func(v flux.Reactor, err error, d interface{}) {
if err != nil {
v.ReplyError(err)
return
}
var data string
var ok bool
if data, ok = d.(string); !ok {
v.ReplyError(ErrInputTytpe)
return
}
var fs *os.File
if fs, err = os.Open(data); err != nil {
v.ReplyError(err)
return
}
if err = parser.ScanChunks(parser.NewScanner(fs), func(query string) {
v.Reply(query)
}); err != nil {
v.ReplyError(err)
}
})
}
示例3: ParseAdaptor
// ParseAdaptor provides a Stacks for parser.Parser to parse stringed queries rather than from a file,it takes a string of a full single query and parses it
func ParseAdaptor(inspect *parser.InspectionFactory) *Parser {
ps := parser.NewParser(inspect)
ad := flux.Reactive(func(v flux.Reactor, err error, d interface{}) {
if err != nil {
v.ReplyError(err)
return
}
var data string
var ok bool
if data, ok = d.(string); !ok {
v.ReplyError(ErrInputTytpe)
return
}
var gs ds.Graphs
if gs, err = ps.Scan(bytes.NewBufferString(data)); err != nil {
v.ReplyError(err)
return
}
v.Reply(gs)
})
return &Parser{
Reactor: ad,
parser: ps,
}
}
示例4: FileAppender
// FileAppender takes the giving data of type FileWriter and appends the value out into a endpoint which is the combination of the name and the toPath value provided
func FileAppender(fx func(string) string) flux.Reactor {
if fx == nil {
fx = defaultMux
}
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if file, ok := data.(*FileWrite); ok {
// endpoint := filepath.Join(toPath, file.Path)
endpoint := fx(file.Path)
endpointDir := filepath.Dir(endpoint)
//make the directory part incase it does not exists
os.MkdirAll(endpointDir, 0700)
osfile, err := os.Open(endpoint)
if err != nil {
root.ReplyError(err)
return
}
defer osfile.Close()
// io.Copy(osfile, file.Data)
osfile.Write(file.Data)
root.Reply(&FileWrite{Path: endpoint})
}
}))
}
示例5: GoRunner
// GoRunner calls `go run` with the command it receives from its data pipes
func GoRunner() flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if cmd, ok := data.(string); ok {
root.Reply(GoRun(cmd))
}
}))
}
示例6: ModFileWrite
// ModFileWrite provides a task that allows building a fileWrite modder,where you mod out the values for a particular FileWrite struct
func ModFileWrite(fx func(*FileWrite)) flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if fw, ok := data.(*FileWrite); ok {
fx(fw)
root.Reply(fw)
}
}))
}
示例7: GoInstallerWith
// GoInstallerWith calls `go install` everysingle time to the provided path once a signal is received
func GoInstallerWith(path string) flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, _ interface{}) {
if err := GoDeps(path); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}))
}
示例8: GoBuilder
// GoBuilder calls `go run` with the command it receives from its data pipes, using the GoBuild function
func GoBuilder() flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if cmd, ok := data.(BuildConfig); ok {
if err := Gobuild(cmd.Path, cmd.Name, cmd.Args); err != nil {
root.ReplyError(err)
}
}
}))
}
示例9: GoArgsBuilderWith
// GoArgsBuilderWith calls `go run` everysingle time to the provided path once a signal is received using the GobuildArgs function
func GoArgsBuilderWith(cmd []string) flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, _ interface{}) {
if err := GobuildArgs(cmd); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}))
}
示例10: GoBuilderWith
// GoBuilderWith calls `go run` everysingle time to the provided path once a signal is received using the GoBuild function
func GoBuilderWith(cmd BuildConfig) flux.Reactor {
validateBuildConfig(cmd)
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, _ interface{}) {
if err := Gobuild(cmd.Path, cmd.Name, cmd.Args); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}))
}
示例11: ByteRenderer
// ByteRenderer provides a baseline worker for building rendering tasks eg markdown. It expects to receive a *RenderFile and then it returns another *RenderFile containing the outputed rendered data with the path from the previous RenderFile,this allows chaining with other ByteRenderers
func ByteRenderer(fx RenderMux) flux.Reactor {
if fx == nil {
panic("RenderMux cant be nil for ByteRender")
}
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if databytes, ok := data.(*RenderFile); ok {
root.Reply(&RenderFile{Path: databytes.Path, Data: fx(databytes.Data)})
}
}))
}
示例12: GoArgsBuilder
// GoArgsBuilder calls `go run` with the command it receives from its data pipes usingthe GobuildArgs function
func GoArgsBuilder() flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if cmd, ok := data.([]string); ok {
if err := GobuildArgs(cmd); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}
}))
}
示例13: GoInstaller
// GoInstaller calls `go install` from the path it receives from its data pipes
func GoInstaller() flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if path, ok := data.(string); ok {
if err := GoDeps(path); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}
}))
}
示例14: FileAllRemover
// FileAllRemover takes a *RemoveFile as the data and removes the path using the os.RemoveAll
func FileAllRemover() flux.Reactor {
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if file, ok := data.(*RemoveFile); ok {
err := os.RemoveAll(file.Path)
if err != nil {
root.ReplyError(err)
return
}
}
}))
}
示例15: BundleAssets
// BundleAssets creates a assets.BindFS, which when it receives any signal, updates the given file from its config
func BundleAssets(config *assets.BindFSConfig) (flux.Reactor, error) {
bindfs, err := assets.NewBindFS(config)
if err != nil {
return nil, err
}
return flux.Reactive(func(root flux.Reactor, err error, data interface{}) {
// bindfs.Record()
if err := bindfs.Record(); err != nil {
root.ReplyError(err)
return
}
root.Reply(true)
}), nil
}