Navigation Menu

Skip to content

Commit

Permalink
farm: support no slices case
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 5, 2015
1 parent 873812b commit 71de200
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/droonga/farm.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Droonga Project
# Copyright (C) 2013-2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -37,12 +37,18 @@ def initialize(name, catalog, loop, options={})
end

def start
n_slices = @slices.size
if n_slices.zero?
on_ready
return
end

n_ready_slices = 0
@slices.each_value do |slice|
slice.on_ready = lambda do
n_ready_slices += 1
if n_ready_slices == @slices.size
@on_ready.call if @on_ready
if n_ready_slices == n_slices
on_ready
end
end
slice.start
Expand All @@ -51,6 +57,11 @@ def start

def stop_gracefully
n_slices = @slices.size
if n_slices.zero?
yield if block_given?
return
end

n_done_slices = 0
@slices.each_value do |slice|
slice.stop_gracefully do
Expand All @@ -71,5 +82,10 @@ def stop_immediately
def process(slice_name, message)
@slices[slice_name].process(message)
end

private
def on_ready
@on_ready.call if @on_ready
end
end
end

0 comments on commit 71de200

Please sign in to comment.