Ticket #147 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

all signals not getting called if disconnect fired in signal

Reported by: spudnyk@gmail.com Assigned to: beau@hartshornesoftware.com
Priority: high Milestone:
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description

the given code should log the following

Creating: child 0
Creating: child 1
Bye from: child 0
Bye from: child 1

but 'Bye from: child 1' is never logged. From looking at the signal implementation the _observers array is a reference that disconnectAll/disconnect mutates when a signal is disconnected, changing the indexes. Changing the signal implementation to copy the array to a local variable rather than a reference before signaling fixes the problem. (this was a fun one to track down!)

var idgen  = imap(partial(operator.add, 'child '), count())
                
var parent = {foo: function(){log('Should Not be called')}}
                
function Child()
{
        this.id = idgen.next()
        log("Creating:", this.id)
}
Child.prototype = {
        bye: function()
        {
                log('Bye from:', this.id)
                // disconnect anything connecting to this
                disconnectAll(this)
        }
}
                
var c1 = new Child()
var c2 = new Child()
connect(c1, 'anysig', parent, 'foo')
connect(c2, 'anysig', parent, 'foo')
connect(parent, 'hello', c1, 'bye')
connect(parent, 'hello', c2, 'bye')
                
// should log bye from child-1 and child-2
signal(parent, 'hello')

Attachments

signal_147.diff (1.1 kB) - added by therve@gmail.com on 10/13/06 06:25:16.

Change History

07/18/06 09:33:36 changed by chris@sixlegs.com

I can confirm that there is funkiness when disconnecting from within an event handler (common in drag&drop). A workaround is to defer disconnecting via setTimeout.

07/19/06 14:48:01 changed by beau@hartshornesoftware.com

  • owner changed from somebody to beau@hartshornesoftware.com.
  • status changed from new to assigned.

08/25/06 16:52:14 changed by beau@hartshornesoftware.com

  • priority changed from normal to high.

10/06/06 08:40:47 changed by beau@hartshornesoftware.com

Added this problem to the test suite: http://trac.mochikit.com/changeset/1150

10/13/06 06:25:16 changed by therve@gmail.com

  • attachment signal_147.diff added.

10/13/06 06:26:02 changed by therve@gmail.com

Attached a patch for correcting the problem. It adds a dependancy on Iter, though.

10/18/06 12:20:06 changed by bob@redivi.com

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in [1169]