Make functions return a channel for parallel processing via go routines.

channelify

GitHub stars GitHub forks

PkgGoDev Test Actions Status Go Report Card MIT license

This library helps you to transform any function into a function that returns a any type to a function that return such types within a channel. This is useful to run in parallel multiple functions and have control on the returned values.

Channelify uses go routines to parallelize the execution of the functions.

The idea comes from Javascript Promisify utility that transforms a callback into a promise.

Installation

go get github.com/ddelizia/channelify

Usage example

Here an example of transforming a simple function in channel so you can execute multiple functions in parallel:

fn := func () string {
    time.Sleep(time.Second * 3)
    return "hello"
}

ch1 := Channelify(fn)
ch2 := Channelify(fn)
chV1 := ch1.(func () chan string)()
chV2 := ch2.(func () chan string)()

v1, v2 := <- chV1, <- chV2

If your functions returns multiple values you can use as follow:

fn1 := func (hello string) (string, error)  {
    time.Sleep(time.Second * 2)
    fmt.Println(hello)
    return hello, nil
}

fn2 := func (hello string) (string, error)  {
    time.Sleep(time.Second * 3)
    fmt.Println(hello)
    return hello, nil
}

ch1 := Channelify(fn1)
ch2 := Channelify(fn2)
chV1, chE1 := ch1.(func (string) (chan string, chan error))("hello1")
chV2, chE2 := ch2.(func (string) (chan string, chan error))("hello2")

v1, e1, v2, e2 := <- chV1, <- chE1, <- chV2, <- chE2

fmt.Print(v1, e1, v2, e2)

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request
Similar Resources

TLDR Page Creator is a program designed to help users make TLDR pages

TLDR Page Creator is a program designed to help users make TLDR pages, while avoiding syntax errors from TLDR-style markdown.

Dec 3, 2022

gevent imply go-event which tries to make event handling easier.

gevent imply go-event which tries to make event handling easier. What does gevent want to do Async execute jobs safely without too many go routines. S

Nov 10, 2021

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it.

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it. today was a HTTP server written with PostGreSQL using Golang, R, and shell script read more

Dec 21, 2021

This application is a tool that allows you to prepare mail designs specific to your group and make Christmas raffles.

What is this? This application is a tool that allows you to prepare mail designs specific to your group and make Christmas raffles. How is it working?

Dec 15, 2022

Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Dec 31, 2021

Haskell-flavoured functions for Go :smiley:

Hasgo Coverage status: gocover.io Our report card: Hasgo is a code generator with functions influenced by Haskell. It comes with some types out-of-the

Dec 25, 2022

Functional programming library for Go including a lazy list implementation and some of the most usual functions.

functional A functional programming library including a lazy list implementation and some of the most usual functions. import FP "github.com/tcard/fun

May 21, 2022

A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Dec 17, 2022

Set of functions/methods that will ease GO code generation

Set of functions/methods that will ease GO code generation

Dec 1, 2021
An easy-to-use Map Reduce Go parallel-computing framework inspired by 2021 6.824 lab1. It supports multiple workers on a single machine right now.

MapReduce This is an easy-to-use Map Reduce Go framework inspired by 2021 6.824 lab1. Feature Multiple workers on single machine right now. Easy to pa

Dec 5, 2022
A simple package for executing work in parallel up to a limit.

concurrencylimiter A simple package for executing work concurrently - up to a limit. The intended usecase looks something like: func concurrentlyDo(ta

Dec 19, 2021
💥 Fusion is a tiny stream processing library written in Go.

?? Fusion Fusion is a tiny stream processing library written in Go. See reactor for a stream processing tool built using fusion. Features Simple & lig

Jun 30, 2021
Processing Nomad Events Stream
Processing Nomad Events Stream

Nomad Events Sink Nomad Events Sink is an events collection agent which uses Nomad Events SDK to fetch events. Events can help debug the cluster state

Dec 19, 2022
Exercise for solve problem data processing, performance and something wrong in passing data

Citcall Exercise Exercise for solve problem data processing, performance and something wrong in passing data Pengolahan data data processing - Readme

Nov 25, 2021
Tidb - An open-source NewSQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads
Tidb - An open-source NewSQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads

What is TiDB? TiDB ("Ti" stands for Titanium) is an open-source NewSQL database

Jan 5, 2022
An unified key management system to make life easier.
An unified key management system to make life easier.

Safebox An unified key management system to make life easier. The main goal of safebox is to make key backup easier with single main key to derive the

Nov 15, 2022
CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonster Cloud API.

✨ CapMonsterTool ✨ About this module What is ✨ CapMonsterTool ✨ ? CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonst

Dec 1, 2022
Default godoc generator - make your first steps towards better code documentation

godoc-generate Overview godoc-generate is a simple command line tool that generates default godoc comments on all exported types, functions, consts an

Sep 14, 2022
Mpq Decoder Golang TODO: MAke Description

MPQ MPQ archive codec Report Bug · Request Feature About This package provides a MPQ archive codec, for compressing and decompressing MoPaQ archives.

Nov 2, 2021