Method: Mongo::BackgroundThread#stop!
- Defined in:
- lib/mongo/background_thread.rb
#stop! ⇒ true | false
Stop the background thread and wait for to terminate for a reasonable amount of time.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mongo/background_thread.rb', line 77 def stop! # If the thread was not started, there is nothing to stop. # # Classes including this module may want to perform additional # cleanup, which they can do by overriding this method. return true unless @thread # Background threads generally perform operations in a loop. # This flag is meant to be checked on each iteration of the # working loops and the thread should stop working when this flag # is set. @stop_requested = true # Besides setting the flag, a particular class may have additional # ways of signaling the background thread to either stop working or # wake up to check the stop flag, for example, setting a semaphore. # This can be accomplished by providing the pre_stop method. pre_stop # Now we have requested the graceful termination, and we could wait # for the thread to exit on its own accord. A future version of the # driver may allow a certain amount of time for the thread to quit. # For now, we additionally use the Ruby machinery to request the thread # be terminated, and do so immediately. # # Note that this may cause the background thread to terminate in # the middle of an operation. @thread.kill wait_for_stop end |