當前位置: 首頁>>代碼示例>>Golang>>正文


Golang flux.Reactive函數代碼示例

本文整理匯總了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
		}

	}))
}
開發者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


注:本文中的github.com/influx6/flux.Reactive函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。