[racket] Asynchronously inserting text to editor%
Thanks for your reply. I've found that `disable`-ing canvas of text editor
when inserting works too. But with downside that you cant select anything
or move the cursor when bulk of text strings are inserted.
26 авг. 2014 г. 7:09 пользователь "Eli Barzilay" <eli at barzilay.org> написал:
> You generally can't do that kind of stuff from a different thread...
> After fighting with this for a while I eventually realized that it's
> not too hard to avoid the extra thread: instead of doing the work
> there, just stick it in a closure that is handed to `queue-callback'.
> (This is based on lessons learned the hard way in an application that
> does a lot of this kind of stuff...)
>
>
> On Sun, Aug 24, 2014 at 5:00 PM, Dmitry Cherkassov
> <dcherkassov at gmail.com> wrote:
> > 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
> >
> http://docs.racket-lang.org/gui/editor___.html#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._editor~3c~25~3e%29._locked-for-flow~3f%29%29
> >
> > 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:
> >
> -------------------------------------------------------------------------------
> >
> > https://github.com/lehitoskin/blight/blob/master/msg-history.rkt#L143
> >
> > `add-recv-message' is called by `on-friend-message':
> > https://github.com/lehitoskin/blight/blob/master/blight.rkt#L956
> >
> > which is called back by `callback-friend-message' C function:
> >
> https://github.com/lehitoskin/libtoxcore-racket/blob/master/functions.rkt#L489
> >
> ----------------------------------------------------------------------------------
> >
> > Thank you.
> >
> > --
> > With best regards,
> > Dmitry
> > ____________________
> > Racket Users list:
> > http://lists.racket-lang.org/users
>
>
>
> --
> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
> http://barzilay.org/ Maze is Life!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140826/2b8f6fc2/attachment-0001.html>