Nothing strikes me as obviously wrong about this code (except the "deferToThread" which seems slightlysuspicious, since nothing in the example appears to have anything to do with threads, and whenever you get threads involved things get complicated).