Every drive deserves an onEnd callback
dracupid opened this issue · 4 comments
dracupid commented
Is it a good idea to let every drive has a onEnd callback, not only writers. For instance, what if I want to count lines of code? Or is there another way to achieve this?
countLine = ->
total = 0
kit._.assign ->
total += @contents.split('\n').length
, onEnd: ->
console.log "Total: #{total} lines。"
ysmood commented
counter = ->
count = 0
{
drive: -> count++
report: -> console.log count
}
c = counter()
kit.warp '*.js'
.load c.drive
.run('dist')
.then ->
c.report()
You need to think things from another aspect. Maybe the user want to control the report by themselves.
dracupid commented
Yes, this is a solution for this example, which is similar with what I'm using now. However, in comparison with Stream, a Transform can always know the end of the stream.
Hmm.., I can't put forward a more powerful use case for no
yet. Closure and then
create more possibilities.
ysmood commented
I've added 3 lines of code. You can pull it and try it yourself first, if everything is OK, I may add it to the next version. 9ccb26e
dracupid commented
Passed. Well done!