| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
Description | |||||||||||||||||||
Tools for tracking the status of a long operation. Written by John Goerzen, jgoerzen@complete.org See also Data.Progress.Meter | |||||||||||||||||||
Synopsis | |||||||||||||||||||
Introduction | |||||||||||||||||||
ProgressTracker is a module for tracking the progress on long-running operations. It can be thought of as the back end engine behind a status bar. ProgressTracker can do things such as track how far along a task is, provide an estimated time of completion, estimated time remaining, current speed, etc. It is designed to be as generic as possible; it can even base its speed calculations on something other than the system clock. ProgressTracker also supports a notion of a parent tracker. This is used when a large task is composed of several individual tasks which may also be long-running. Downloading many large files over the Internet is a common example of this. Any given ProgressTracker can be told about one or more parent trackers. When the child tracker's status is updated, the parent tracker's status is also updated in the same manner. Therefore, the progress on each individual component, as well as the overall progress, can all be kept in sync automatically. Finally, you can register callbacks. Callbacks are functions that are called whenever the status of a tracker changes. They'll be passed the old and new status and are intended to do things like update on-screen status displays. The cousin module Data.Progress.Meter can be used to nicely render these trackers on a console. | |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
Create a new Progress object initialized with the given status and callbacks. No adjustment to the startTime will be made. If you want to use the system clock, you can initialize startTime with the return value of defaultTimeSource and also pass defaultTimeSource as the timing source. | |||||||||||||||||||
| |||||||||||||||||||
Adds an new callback to an existing Progress. The callback will be called whenever the object's status is updated, except by the call to finishP. Please note that the Progress object will be locked while the callback is running, so the callback will not be able to make any modifications to it. | |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
Updating | |||||||||||||||||||
| |||||||||||||||||||
Increment the completed unit count in the Progress object by the amount given. If the value as given exceeds the total, then the total will also be raised to match this value so that the completed count never exceeds the total. You can decrease the completed unit count by supplying a negative number here. | |||||||||||||||||||
| |||||||||||||||||||
Like incrP, but never modify the total. | |||||||||||||||||||
| |||||||||||||||||||
Set the completed unit count in the Progress object to the specified value. Unlike incrP, this function sets the count to a specific value, rather than adding to the existing value. If this value exceeds the total, then the total will also be raised to match this value so that the completed count never exceeds teh total. | |||||||||||||||||||
| |||||||||||||||||||
Like setP, but never modify the total. | |||||||||||||||||||
| |||||||||||||||||||
Increment the total unit count in the Progress object by the amount given. This would rarely be needed, but could be needed in some special cases when the total number of units is not known in advance. | |||||||||||||||||||
| |||||||||||||||||||
Set the total unit count in the Progress object to the specified value. Like incrTotal, this would rarely be needed. | |||||||||||||||||||
| |||||||||||||||||||
Call this when you are finished with the object. It is especially important to do this when parent objects are involved. This will simply set the totalUnits to the current completedUnits count, but will not call the callbacks. It will additionally propogate any adjustment in totalUnits to the parents, whose callbacks will be called. This ensures that the total expected counts on the parent are always correct. Without doing this, if, say, a transfer ended earlier than expected, ETA values on the parent would be off since it would be expecting more data than actually arrived. | |||||||||||||||||||
Reading and Processing | |||||||||||||||||||
| |||||||||||||||||||
Returns the speed in units processed per time unit. (If you are using the default time source, this would be units processed per second). This obtains the current speed solely from analyzing the Progress object. If no time has elapsed yet, returns 0. You can use this against either a Progress object or a ProgressStatus object. This is in the IO monad because the speed is based on the current time. Example: getSpeed progressobj >>= print Don't let the type of this function confuse you. It is a fancy way of saying that it can take either a Progress or a ProgressStatus object, and returns a number that is valid as any Fractional type, such as a Double, Float, or Rational. | |||||||||||||||||||
| |||||||||||||||||||
Returns the estimated time remaining, in standard time units. Returns 0 whenever getSpeed would return 0. See the comments under getSpeed for information about this function's type and result. | |||||||||||||||||||
| |||||||||||||||||||
Returns the estimated system clock time of completion, in standard time units. Returns the current time whenever getETR would return 0. See the comments under getSpeed for information about this function's type and result. | |||||||||||||||||||
Types | |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
A function that, when called, yields the current time. The default is defaultTimeSource. | |||||||||||||||||||
| |||||||||||||||||||
The type for a callback function for the progress tracker. When given at creation time to 'newProgress\'' or when added via addCallback, these functions get called every time the status of the tracker changes. This function is passed two ProgressStatus records: the first reflects the status prior to the update, and the second reflects the status after the update. Please note that the owning Progress object will be locked while the callback is running, so the callback will not be able to make changes to it. | |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
Utilities | |||||||||||||||||||
| |||||||||||||||||||
The default time source for the system. This is defined as: getClockTime >>= (return . clockTimeToEpoch) | |||||||||||||||||||
Produced by Haddock version 2.6.0 |