Compartilhar via


Persistent Settings Update

Soon after I posted my persistent settings library, I received my first bug on it.  I'll discuss the bug a bit, but first things first - the bug is fixed, and the links updated; if you previously downloaded the library, please go ahead and get the updated version.

Details:

The symptom of the bug was that the following two consecutive calls:

 getPersistentSetting( "setting", firstCallback );
getPersistentSetting( "setting", secondCallback );

Would result in two calls on the 'secondCallback' function.  The failure itself made it clear to me where the error was; and the location of the error suggested the fix.  I'm afraid I don't know enough about the intricacies of the javascript language to know exactly why it failed in the first place, though; perhaps one of my more knowledgable readers will chime in.

Here is the failing code:

 window.setTimeout(function ()
{
    try
    {
        workItem.callback(returnValue);
    }
    catch (e)
    {
        persistentSettingLog("exception from callback: " + e.name + ": " + e.message);
    }
}, 0);

And here is the fixed version:

 persistentSettingScheduleCallback(workItem.callback, returnValue);
function persistentSettingScheduleCallback(callback, returnValue)
{
    window.setTimeout(function ()
    {
        try
        {
            callback(returnValue);
        }
        catch (e)
        {
            persistentSettingLog("exception from callback: " + e.name + ": " + e.message);
        }
    }, 0);
}

Comments