Last active
December 18, 2015 11:38
-
-
Save amiel/5776777 to your computer and use it in GitHub Desktop.
ARC vs GC gotcha example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe WebService | |
def test_request(t, path, params, &block) | |
# Local variable t persists in both callbacks | |
# However, `block` doesn't make it | |
@result = nil | |
WebService.post(path, params) do |result| | |
@result = result | |
t.resume | |
end | |
t.wait_max 0.2 do | |
# `block` is `nil` | |
block.call(@result) | |
end | |
end | |
it 'test example' do | |
test_request(self, 'path', 'pin' => '123456') do |result | |
result.should.be.success | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe WebService | |
# This example works as expected. See notes | |
def test_request(t, path, params, block) | |
# Local variables t, and block persist in both callbacks | |
# @request persists in both callbacks | |
@result = nil | |
WebService.post(path, params) do |result| | |
@result = result | |
t.resume | |
end | |
t.wait_max 0.2 do | |
block.call(@result) | |
end | |
end | |
it 'test example' do | |
test_request(self, 'path', 'pin' => '123456', ->(result) { | |
result.should.be.success | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment