ruby-mpd icon indicating copy to clipboard operation
ruby-mpd copied to clipboard

Add a function to temporarily disable callbacks

Open specht opened this issue 9 years ago • 1 comments

When I'm adding a lot of songs one by one (which as far as I can see can't be done any other way), the :playlist callback gets fired multiple times, which is correct. But it would be nice to be able to temporarily disable callbacks for potentially long operations, like this:

class MPD
  def no_callbacks(&block)
    # pause callback thread (or stop it)
    yield
    # resume callback thread (or restart it)
  end
end

mpd.no_callbacks do
  # add many songs here
end
# :playlist callback gets fired here

This way, my client would get the updated playlist when it's finished and wouldn't have to process multiple incomplete updates. At the end of the provided block, the callback thread would resume as usual and emit all changed keys. This requires that the callback cannot only be stopped, but also resumed (or stopped and then restarted).

Any feedback would be appreciated!

specht avatar Oct 26 '15 21:10 specht

You can add songs based on a search and it will only emit one :playlist event:

mpd.where({artist: 'MyArtiSt'}, {add: true})

mikerodrigues avatar Nov 03 '15 06:11 mikerodrigues