美文网首页
Repeat pipline

Repeat pipline

作者: FredricZhu | 来源:发表于2019-06-17 11:33 被阅读0次
package main

import (
    "fmt"
)

func main() {
    repeat := func(
        done <-chan interface{},
        values ...interface{},
    ) <-chan interface{} {
        valueStream := make(chan interface{})
        go func() {
            defer close(valueStream)
            for {
                for _, v := range values {
                    select {
                    case <-done:
                        return
                    case valueStream <- v:
                    }
                }
            }
        }()
        return valueStream
    }

    take := func(
        done <-chan interface{},
        valueStream <-chan interface{},
        num int,
    ) <-chan interface{} {
        takeStream := make(chan interface{})
        go func() {
            defer close(takeStream)
            for i := 0; i < num; i++ {
                select {
                case <-done:
                    return
                case takeStream <- <-valueStream:
                }
            }
        }()
        return takeStream

    }

    done := make(chan interface{})
    defer close(done)

    for num := range take(done, repeat(done, 1, 2, 3, 4), 10) {
        fmt.Printf("%v ", num)
    }

    fmt.Println()

}

程序输出如下,


image.png

相关文章

  • Repeat pipline

    程序输出如下,

  • jenkins:pipline流水线基础

    什么是Pipline?Pipline是一套运行在jenkins的工作流框架,通过使用pipline,可以将独立的节...

  • Linux服务器环境部署系列09

    基础组件安装: 一、使用jenkins的pipline管道方式进行构建 1、【新建】——》【pipline】,随便...

  • css 之background (三)

    background-repeat: repeat-x | repeat-y | [repeat | no-rep...

  • xargs和pipline管道

    pipline管道 xargs 经常配合find使用,find根本不支持pipline |,太不方便了。 xarg...

  • scrapy自定义Pipline

    第一个事mysql 同步Pipline,适用爬虫量小 异步mysql 的pipline, 适用爬虫量大。 自定义...

  • learn English_01

    Words advice 1. Repeat, Repeat, Repeat… 2. Poster / stick...

  • css:background

    1.背景图片的平铺 background-repeat:repeat,repeat-y,repeat-x,no-r...

  • 图像

    重复图像background-repeat repeat:水平垂直方向都会重复图像 repeat-x:....

  • CSS基础样式

    CSS背景 background-repeat:设置背景是否重复。 no-repeat 不重复 repeat-x ...

网友评论

      本文标题:Repeat pipline

      本文链接:https://www.haomeiwen.com/subject/vftafctx.html