aparajita/Cup

Cup is not "reentrant"

Closed this issue · 1 comments

Since the Cup object is not a singleton it should be possible to allocate it in more than one instance. Right now this does not work because of the file variable 'callbacks'. This variable is set only once with the callback functions the jQuery.fileUpload script uses to message the Cup object. The method 'setCallbacks:' is implemented to set the variable and if called a second time it is not creating new functions but is setting the 'options' with those functions that where set the first time.

This effectively hinders the Cup object to function in more than one instance since the functions contains messages sent to 'self'. The 'self' object is copied into the function and therefore all callbacks will use the first allocated object as 'self'. So all instances of Cup will call the first allocated Cup object when called back.
See:

    callbacks =
    {
        add: function(e, data)
        {
            currentEvent = e;
            currentData = data;
            [self addFile:data.files[0]];
            [self pumpRunLoop];
        },

......

Here ' [self addFile:data.files[0]];' will be sent to the first instance allocated from the Cup class.

By making the 'callbacks' variable local to the method and removing the test if not nil it will probably be fixed.

Good point, but the solution is to make callbacks an ivar instead of a file var. No change is necessary to setCallbacks.