# Help refactoring deprecated Task() to Channels

**URL:** <https://discourse.julialang.org/t/help-refactoring-deprecated-task-to-channels/10576>\
**Category:** New to Julia\
**Created:** [April 27, 2018, 2:32pm UTC](https://discourse.julialang.org/t/help-refactoring-deprecated-task-to-channels/10576 "2018-04-27T14:32:20Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Joshua\_Bowles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_bowles/32/4515_2.png) [@Joshua\_Bowles](https://discourse.julialang.org/u/Joshua_Bowles)\
**Post date:** [April 27, 2018, 3:21pm UTC](https://discourse.julialang.org/t/help-refactoring-deprecated-task-to-channels/10576/4 "2018-04-27T15:21:03Z")

</div>

Sure enough, simple and works.  
I’m gonna work it a bit. In go I’d typically have a goroutine per file or per batch of files. I imagine i’d have to rework it quite a bit if I wanted to run a channel on multiple cpu to large sets of files, per the discourse post here: [reading-and-processing-data-files-concurrently](https://discourse.julialang.org/t/reading-and-processing-data-files-concurrently/5972/18)

Thank you again.

I did noticed if I put the `Channel() do` block under scope of the `for (root, dirs, files) in walkdir(path)` block i get an error.

```julia
ERROR: MethodError: no method matching start(::Void)
Closest candidates are:
  start(::SimpleVector) at essentials.jl:258
  start(::Base.MethodList) at reflection.jl:560
  start(::ExponentialBackOff) at error.jl:107

```

Here is the refactored bit:

```julia
function readFile(path::String)
    Channel() do chan
        for (root, dirs, files) in walkdir(path)
            for filename in files 
                if !(filename in SKIPFILES) && filename[1] != '.'
                    fullname = joinpath(root, filename)
                    if isfile(fullname)
                        pastHeader, lines = false, Vector{String}()
                        open(fullname) do f 
                            for line in eachline(f)
                                if !isvalid(line)
                                    line = decode(convert(Array{UInt8,1}, line), "LATIN1")
                                end
                                line = chomp(line)
                                if pastHeader
                                    push!(lines, line)
                                elseif endof(line) == 0
                                    pastHeader = true
                                end
                            end
                        end
                        content = join(lines, NEWLINE)
                        put!(chan, (fullname,content))
                    end
                end
            end
        end
    end
end

function addData!(df::DataFrame, path::String, classification::String)
    for (filename, text) in readFile(path)
        push!(df, @data([text, classification, filename]))
    end
end

function buildDataSet(sources)
    df = DataFrame(text = Vector{String}(), class = Vector{String}(), index = Vector{String}())
    for (path, classification) in sources
        addData!(df, joinpath(SPAMROOT, path), classification)
    end
    return df
end

```

---

_[View the full topic](https://discourse.julialang.org/t/help-refactoring-deprecated-task-to-channels/10576)._
