digital-fabric / extralite

Ruby on SQLite
http://www.rubydoc.info/gems/extralite
MIT License
255 stars 8 forks source link

Improve on_progress #68

Closed noteflakes closed 9 months ago

noteflakes commented 9 months ago

This PR introduces some improvements to the progress handler functionality:

The tick parameter is used to control the granularity of the progress handler. This is the value passed to sqlite3_progress_handler. The period parameter is used to control how often the progress handler proc is called. So, a period of 1000 and a tick of 10 will cause the internal progress handler callback to be called every 10 SQLite VM instructions, but the proc will be called only every 1000 (cumulative) VM instructions.

The different modes:

Some examples:

# tick default value: 10
db.on_progress(1000) { snooze }

db.on_progress(mode: :once) { snooze }

Extralite.on_progress(mode: :at_least_once, period: 100, tick: 5) { snooze }