mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Return the pop'ed Buffer from the BufferStack on flush_and_pop
This commit is contained in:
parent
248a1d558f
commit
7a32781c17
@ -54,11 +54,12 @@ module Rackstash
|
||||
# If there was a buffer on the stack and it has pending data, it is flushed
|
||||
# to the {#sink} before it is returned.
|
||||
#
|
||||
# @return [nil]
|
||||
# @return [Buffer, nil] the removed {Buffer} or `nil` if there was no
|
||||
# {Buffer} to remove
|
||||
def flush_and_pop
|
||||
buffer = @stack_mutex.synchronize { @stack.pop }
|
||||
buffer = @stack.pop
|
||||
buffer.flush if buffer
|
||||
nil
|
||||
buffer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -70,9 +70,9 @@ describe Rackstash::BufferStack do
|
||||
.not_to change { stack.instance_variable_get(:@stack) }
|
||||
end
|
||||
|
||||
it 'always returns nil' do
|
||||
it 'returns the pop\'ed Buffer' do
|
||||
stack.push
|
||||
expect(stack.flush_and_pop).to be nil
|
||||
expect(stack.flush_and_pop).to be_a Rackstash::Buffer
|
||||
expect(stack.flush_and_pop).to be nil
|
||||
end
|
||||
|
||||
|
||||
@ -597,6 +597,10 @@ describe Rackstash::Logger do
|
||||
logger.add 0, 'I feel great'
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns the yielded value' do
|
||||
expect(logger.with_buffer { :hello }).to eql :hello
|
||||
end
|
||||
end
|
||||
|
||||
context 'with multiple threads' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user