## ズンドコキヨシ¶

In [1]:
function zundokochannel()
function _producer(channel::Channel{String})
i = 1
while i > 0
zd, i = rand([("ズン", i + 1), ("ドコ", +(i<5))])
put!(channel, zd)
end
put!(channel, "キ・ヨ・シ！")
close(channel)
end
channel = Channel{String}(32)
@schedule _producer(channel)
channel
end

Out[1]:
zundokochannel (generic function with 1 method)
In [2]:
for cw in zundokochannel()
print(cw)
end

ズンドコズンズンドコドコドコドコドコドコドコドコドコドコズンズンドコドコズンズンズンズンズンドコキ・ヨ・シ！
In [3]:
collect(zundokochannel())

Out[3]:
82-element Array{String,1}:
"ドコ"
"ズン"
"ズン"
"ドコ"
"ドコ"
"ズン"
"ドコ"
"ズン"
"ズン"
"ドコ"
"ズン"
"ズン"
"ドコ"
⋮
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ドコ"
"ズン"
"ズン"
"ズン"
"ズン"
"ズン"
"ドコ"
"キ・ヨ・シ！"

### ズンドコキヨシ（厳密版）¶

In [4]:
function zundokostrictchannel()
function _producer(channel::Channel{String})
i = 1
while i > 0
zd, i = rand([("ズン", i + 1), ("ドコ", +(i!=5))])
put!(channel, zd)
end
put!(channel, "キ・ヨ・シ！")
close(channel)
end
channel = Channel{String}(32)
@schedule _producer(channel)
channel
end

Out[4]:
zundokostrictchannel (generic function with 1 method)
In [5]:
for cw in zundokostrictchannel()
print(cw)
end

ズンドコズンドコドコドコズンドコドコズンズンドコドコドコドコドコズンドコドコドコズンズンドコズンズンドコズンズンズンズンドコキ・ヨ・シ！
In [6]:
collect(zundokostrictchannel())

Out[6]:
51-element Array{String,1}:
"ズン"
"ドコ"
"ズン"
"ズン"
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ズン"
"ズン"
"ズン"
"ズン"
"ドコ"
⋮
"ドコ"
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ドコ"
"ズン"
"ズン"
"ズン"
"ズン"
"ドコ"
"キ・ヨ・シ！"

### ズンドコキヨシ（for v0.6.x）¶

In [7]:
VERSION

Out[7]:
v"0.6.1"
In [8]:
function zundokochannel_v06()
Channel(ctype=String, csize=32) do channel::Channel{String}
i = 1
while i > 0
zd, i = rand([("ズン", i + 1), ("ドコ", +(i<5))])
put!(channel, zd)
end
put!(channel, "キ・ヨ・シ！")
end
end

Out[8]:
zundokochannel_v06 (generic function with 1 method)
In [9]:
for cw in zundokochannel_v06()
print(cw)
end

ズンズンドコドコドコドコズンズンドコドコズンドコドコズンズンズンズンドコキ・ヨ・シ！
In [10]:
collect(zundokochannel_v06())

Out[10]:
27-element Array{String,1}:
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ズン"
"ドコ"
"ズン"
"ドコ"
"ドコ"
"ズン"
"ドコ"
"ズン"
"ズン"
⋮
"ズン"
"ドコ"
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ズン"
"ズン"
"ズン"
"ズン"
"ドコ"
"キ・ヨ・シ！"

In [11]:
function zundokotask()
function _producer()
i = 1
while i > 0
zd, i = rand([("ズン", i + 1), ("ドコ", +(i<5))])
produce(zd)
end
produce("キ・ヨ・シ！")
end
end

Out[11]:
zundokotask (generic function with 1 method)
In [12]:
for cw in zundokotask()
print(cw)
end

WARNING: Task iteration is now deprecated. Use Channels for inter-task communication.  A for-loop on a Channel object is terminated by calling close on the object.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] start at ./deprecated.jl:986 [inlined]
[3] anonymous at ./<missing>:?
[5] include_string(::Module, ::String, ::String) at /path/to/userhome/.julia/v0.6/Compat/src/Compat.jl:174
[6] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /path/to/userhome/.julia/v0.6/IJulia/src/execute_request.jl:154
[7] eventloop(::ZMQ.Socket) at /path/to/userhome/.julia/v0.6/IJulia/src/eventloop.jl:8
WARNING: consume is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[3] done at ./deprecated.jl:992 [inlined]
[4] anonymous at ./<missing>:?
[6] include_string(::Module, ::String, ::String) at /path/to/userhome/.julia/v0.6/Compat/src/Compat.jl:174
[7] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /path/to/userhome/.julia/v0.6/IJulia/src/execute_request.jl:154
[8] eventloop(::ZMQ.Socket) at /path/to/userhome/.julia/v0.6/IJulia/src/eventloop.jl:8

ドコズンドコドコドコドコズンズンドコドコドコドコドコズンズンズンドコズンズンズンズンズンズンズンズンズンズンドコキ・ヨ・シ！
WARNING: produce is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] produce(::String) at ./deprecated.jl:909
[3] (::#_producer#10)() at ./In[11]:6
WARNING: produce is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] produce(::String) at ./deprecated.jl:909
[3] (::#_producer#10)() at ./In[11]:8

In [13]:
collect(zundokotask())

WARNING: Task iteration is now deprecated. Use Channels for inter-task communication.  A for-loop on a Channel object is terminated by calling close on the object.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] start at ./deprecated.jl:986 [inlined]
[6] include_string(::Module, ::String, ::String) at /path/to/userhome/.julia/v0.6/Compat/src/Compat.jl:174
[7] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /path/to/userhome/.julia/v0.6/IJulia/src/execute_request.jl:154
[8] eventloop(::ZMQ.Socket) at /path/to/userhome/.julia/v0.6/IJulia/src/eventloop.jl:8
WARNING: consume is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[3] done at ./deprecated.jl:992 [inlined]
[4] grow_to!(::Array{Union{},1}, ::Task, ::Void) at ./array.jl:531
[8] include_string(::Module, ::String, ::String) at /path/to/userhome/.julia/v0.6/Compat/src/Compat.jl:174
[9] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /path/to/userhome/.julia/v0.6/IJulia/src/execute_request.jl:154
[10] eventloop(::ZMQ.Socket) at /path/to/userhome/.julia/v0.6/IJulia/src/eventloop.jl:8
WARNING: produce is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] produce(::String) at ./deprecated.jl:909
[3] (::#_producer#10)() at ./In[11]:6
WARNING: produce is now deprecated. Use Channels for inter-task communication.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] produce(::String) at ./deprecated.jl:909
[3] (::#_producer#10)() at ./In[11]:8

Out[13]:
19-element Array{String,1}:
"ドコ"
"ドコ"
"ズン"
"ドコ"
"ドコ"
"ドコ"
"ドコ"
"ドコ"
"ドコ"
"ズン"
"ズン"
"ドコ"
"ドコ"
"ズン"
"ズン"
"ズン"
"ズン"
"ドコ"
"キ・ヨ・シ！"
In [ ]: