Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Try completion block
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgreen committed Feb 9, 2014
1 parent 52aeee9 commit 9eba7dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
17 changes: 11 additions & 6 deletions spec/elevate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ class TestController
include Elevate

def initialize
@invocations = ThreadsafeProxy.new({})
@invocations = {}
@counter = 0
@threads = []
@updates = []
@callback_args = nil
@completion = nil
end

attr_accessor :started
Expand All @@ -17,6 +18,7 @@ def initialize
attr_accessor :threads
attr_accessor :updates
attr_accessor :callback_args
attr_accessor :completion

task :cancellable do
background do
Expand Down Expand Up @@ -119,6 +121,8 @@ def initialize
on_finish do |result, ex|
self.invocations[:finish] = counter
self.counter += 1

@completion.call if @completion
end
end
end
Expand Down Expand Up @@ -270,9 +274,10 @@ def initialize
stub_request(:get, "http://example.com/").
to_return(body: "Hello!", content_type: "text/plain")

@controller.completion = -> { resume }
@controller.launch(:timeout_test)

wait 0.5 do
wait_max 0.9 do
@controller.invocations[:timeout].should.be.nil
@controller.invocations[:finish].should.not.be.nil
end
Expand All @@ -282,10 +287,10 @@ def initialize
stub_request(:get, "http://example.com/").
to_return(body: "Hello!", content_type: "text/plain", delay: 1.0)

@controller.completion = -> { resume }
@controller.launch(:timeout_test)

wait 0.5 do
p @controller
wait_max 0.9 do
@controller.invocations[:finish].should.not.be.nil
end
end
Expand All @@ -294,10 +299,10 @@ def initialize
stub_request(:get, "http://example.com/").
to_return(body: "Hello!", content_type: "text/plain", delay: 1.0)

@controller.completion = -> { resume }
@controller.launch(:timeout_test)

wait 0.5 do
p @controller
wait_max 0.9 do
@controller.invocations[:timeout].should.not.be.nil
end

Expand Down
18 changes: 0 additions & 18 deletions spec/support/threadsafe_proxy.rb

This file was deleted.

0 comments on commit 9eba7dc

Please sign in to comment.