本文整理汇总了Golang中github.com/influx6/flux.Reactive函数的典型用法代码示例。如果您正苦于以下问题:Golang Reactive函数的具体用法?Golang Reactive怎么用?Golang Reactive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Reactive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:30,代码来源:builders.go
示例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)
}
})
}
开发者ID:influx6,项目名称:dataquery,代码行数:29,代码来源:adaptors.go
示例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,
}
}
开发者ID:influx6,项目名称:dataquery,代码行数:33,代码来源:adaptors.go
示例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})
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:31,代码来源:fs.go
示例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))
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:8,代码来源:builders.go
示例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)
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:9,代码来源:fs.go
示例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)
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:10,代码来源:builders.go
示例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)
}
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:10,代码来源:builders.go
示例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)
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:10,代码来源:builders.go
示例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)
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:11,代码来源:builders.go
示例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)})
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:11,代码来源:builders.go
示例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)
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:12,代码来源:builders.go
示例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)
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:12,代码来源:builders.go
示例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
}
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:13,代码来源:fs.go
示例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
}
开发者ID:influx6,项目名称:reactors,代码行数:17,代码来源:builders.go
示例16: QueryAdaptor
// QueryAdaptor provides a simple sql parser
func QueryAdaptor(gx QueryHandler) flux.Reactor {
return flux.Reactive(func(v flux.Reactor, err error, d interface{}) {
if err != nil {
v.ReplyError(err)
return
}
da, ok := d.(ds.Graphs)
if !ok {
v.ReplyError(ErrGraphType)
return
}
gx(v, da)
})
}
开发者ID:influx6,项目名称:dataquery,代码行数:18,代码来源:adaptors.go
示例17: DbExecutor
//DbExecutor returns a reactor that takes a sql.Db for execution of queries
func DbExecutor(db *sql.DB) flux.Reactor {
return flux.Reactive(func(r flux.Reactor, err error, d interface{}) {
if err != nil {
r.ReplyError(err)
return
}
var stl *Statement
var ok bool
if stl, ok = d.(*Statement); !ok {
r.ReplyError(ErrInvalidStatementType)
return
}
rows, err := db.Query(stl.Query)
if err != nil {
r.ReplyError(err)
return
}
var datarows [][]interface{}
defer rows.Close()
for rows.Next() {
bu := adaptors.BuildInterfacePoints(stl.Columns)
err := rows.Scan(bu...)
if err != nil {
r.ReplyError(err)
return
}
datarows = append(datarows, bu)
}
stl.Data = adaptors.UnbuildInterfaceList(datarows)
r.Reply(stl)
})
}
开发者ID:influx6,项目名称:dataquery,代码行数:44,代码来源:sql.go
示例18: CommandLauncher
// CommandLauncher returns a new Task generator that builds a command executor that executes a series of command every time it receives a signal, it sends out a signal onces its done running all commands
func CommandLauncher(cmd []string) flux.Reactor {
var channel chan bool
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, _ interface{}) {
if channel == nil {
channel = RunCMD(cmd, func() {
root.Reply(true)
})
}
select {
case <-root.CloseNotify():
close(channel)
return
case <-time.After(0):
channel <- true
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:20,代码来源:builders.go
示例19: FileOpCopy
// FileOpCopy listens for either a FilRead or FileWrite and send that off to a given set of reactors, to reduce memory footprint the FilRead/FileWrite pointer is sent as is, so if you want a fresh copy, dereference it to have a unique copy
func FileOpCopy(to ...flux.Reactor) flux.Reactor {
return flux.Reactive((func(root flux.Reactor, err error, data interface{}) {
if err != nil {
for _, fx := range to {
fx.SendError(err)
}
return
}
if file, ok := data.(*FileWrite); ok {
for _, fx := range to {
fx.Send(file)
}
}
if file, ok := data.(*FileRead); ok {
for _, fx := range to {
fx.Send(file)
}
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:23,代码来源:fs.go
示例20: GoFileLauncher
// GoFileLauncher 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 GoFileLauncher(goFile string, args []string) flux.Reactor {
var channel chan bool
return flux.Reactive(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
if channel == nil {
channel = RunGo(goFile, args, func() {
root.Reply(true)
}, func() {
go root.Close()
})
}
select {
case <-root.CloseNotify():
close(channel)
return
case <-time.After(0):
channel <- true
}
}))
}
开发者ID:influx6,项目名称:reactors,代码行数:23,代码来源:builders.go
注:本文中的github.com/influx6/flux.Reactive函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论