Re: [code] [textadept] Patch for events

From: D K <mccoy.att.doctor.com>
Date: Thu, 14 Jul 2016 23:03:22 +0200

> Thanks for bringing this to my attention :) I've applied something similar[1]. It turns out juggling handler indices really isn't necessary. Cheers, Mitchell [1]: http://foicica.com/hg/textadept/rev/ecbc553cbbc7

Thanks, it's nice to see a fix so soon, even though not many people can have been affected by those two issues in the past. Yes, your solution is more compact (source code-wise) and easier to read.

I think there might be another corner-case in core/events. I guess even fewer users are affected by it, but it may be good to know:

The scenario is when events.connect() is used to add some new callback for the same event (type) that is currently being processed by events.emit. Since the length of the sequence of event callbacks is evaluated when the for-loop in events.emit starts (the line "for i = 1, #h"), you won't process the callbacks after that point (the original value of #h).

If new event callbacks happen to be appended to the sequence (after the original value of #h), then all this can be written off as a feature and not a defect, but if inserting new callbacks in the middle of the sequence, there are some original event callbacks in h that should have been executed in this invocation of events.emit that we never get to process.

There are of course many different ways of dealing with this. Here are some ideas off the top of my head:

1) Ignore the problem, it's too much of a corner-case. (Probably ok)
2) Only allow appending events and not inserting events at other positions while events.emit is running. (Yuck!)
3) Check after processing the sequence in events.emit that it has grown. Before for-loop, cache old value of #h and re-check new value of #h after the for-loop is done, process any remaining ones. (Pragmatic, and unlikely to need a lot of code changes)
4) Delay adding/deleting events while events.emit is running and perform those delayed operations immediately (or very soon) after the for-loop in events.emit has finished. (Nice one, but probably requires more code changes and there might be some side-effects I've not thought of).

/David Karell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 14 Jul 2016 - 17:03:22 EDT

This archive was generated by hypermail 2.2.0 : Fri 15 Jul 2016 - 06:33:42 EDT