[racket] Asynchronously inserting text to editor%

From: Dmitry Cherkassov (dcherkassov at gmail.com)
Date: Sun Aug 24 17:00:55 EDT 2014

Hi. I am asyncrhonously insert text strings to editor% (from another thread)

The problem is that i sometimes get this exception from object of editor% class:

sequence-contract-violation: negative: method insert cannot be called,
except in states (unlocked)

I've tried to loop while editor is locked calling these functions

But it seems they do not work for me (do not return if editor is
locked) and still that exception in caused.

I've fallen back to ugly loop then.

(define retry (call/cc (lambda (k) k)))

(with-handlers ([exn:fail?
                 (lambda (ex)
                   (sleep 1)
                   (retry retry))])
               (send editor insert message))

Is there a better way?

P.S Full source code for that stuff is available there:


`add-recv-message' is called by `on-friend-message':

which is called back by `callback-friend-message' C function:

Thank you.

With best regards,

Posted on the users mailing list.