Ejemplo n.º 1
0
// run the article through the pipeline
func runArticle(pipe *pipeline.Pipeline, article string) ([]analyzer.Analyzable, error) {
	story, err := buildStory(article)
	if err != nil {
		panic(err)
	}

	pipe.Start()
	pipe.PushStory(story)

	var result pipeline.Story

	select {
	case result = <-pipe.GetOutput():
		break

	case <-pipe.Error():
		// go get the error when you actually close the pipe
		err := pipe.Close()
		return nil, err
	}

	var related []analyzer.Analyzable

	for {
		select {
		case analyzed, open := <-result.RelatedArticles:
			if !open {
				return related, pipe.Close()
			}
			related = append(related, analyzed)

		case <-pipe.Error():
			// get the error when you close the pipe
			err := pipe.Close()
			return nil, err
		}
	}
}
Ejemplo n.º 2
0
// manages running a story
func storyDriver(
	pipe *pipeline.Pipeline,
	story pipeline.Story) ([]pipeline.Article, error) {

	pipe.Start()
	pipe.PushStory(story)

	var result pipeline.Story

	select {
	case result = <-pipe.GetOutput():
		break

	case <-pipe.Error():
		// go get the error when you actually close the pipe
		err := pipe.Close()
		return nil, err
	}

	related := make([]pipeline.Article, 0)

	for {
		select {
		case analyzed, open := <-result.RelatedArticles:
			if !open {
				return related, pipe.Close()
			}
			related = append(related, analyzed)

		case <-pipe.Error():
			// get the error when you close the pipe
			err := pipe.Close()
			return nil, err
		}
	}
}