Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend stdlib queue for the test queue
- Loading branch information
1 parent
673fe05
commit 2187b5f
Showing
2 changed files
with
12 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,27 +7,11 @@ module Queueing | |
# | ||
# Jobs are run in a separate thread to catch mistakes where code | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
josevalim
Contributor
|
||
# assumes that the job is run in the same thread. | ||
class TestQueue | ||
attr_reader :contents | ||
|
||
def initialize | ||
@contents = [] | ||
end | ||
|
||
class TestQueue < ::Queue | ||
def drain | ||
# run the jobs in a separate thread so assumptions of synchronous | ||
# jobs are caught in test mode. | ||
t = Thread.new do | ||
while job = @contents.shift | ||
job.run | ||
end | ||
end | ||
t.join | ||
end | ||
|
||
# implement the Queue API | ||
def push(object) | ||
@contents << object | ||
Thread.new { pop.run until empty? }.join | ||
end | ||
end | ||
|
||
|
This file contains 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
Bro, you forgot to update the documentation. It was saying explicitly there is a method contents you could call to get the jobs added.