edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [Edbrowse-dev] An Asynchronous Experiment
@ 2015-09-18 19:46 Karl Dahlke
  0 siblings, 0 replies; only message in thread
From: Karl Dahlke @ 2015-09-18 19:46 UTC (permalink / raw)
  To: Edbrowse-dev

Ok folks, this is fun.
My last push implements javascript timers and intervals.
Not the way we had it before, where a timer turns into a hyperlink,
and you can push the button if you want to run the code under the timer,
and some web pages had dozens of timers,
cluttering the page with dozens of hyperlinks,
and you had no idea if you should push them or in what order or whatever,
not like that, but real timers that fire when they're suppose to,
and run the javascript that they're suppose to,
all in the background.

I'm not saying this is the end all design, but for 150 lines of code
it works, and I kinda like it.
It is engine independent.
In other words, the timer code is this side of jseng-moz.cpp,
working through the primitives in ebjs.c.
So if we switch to duktape or whatever we won't have to change
any of the timer code.

I have database experience, so I made it transaction like.
edbrowse is either running your command, with perhaps some attendant javascript,
or it is running a timer, but the two cannot overlap in time.
There are no nasty race conditions or window collisions.

Timers can run on any window in edbrowse with active javascript,
in any of the buffers, even a background window.
Changes made to the screen are seen if you switch to that window,
or if you type rr for the current foreground window.

jsrt has always had a timer in it for testing.
As mentioned earlier, that timer just turned into a hyperlink,
which wasn't very interesting.
Now it runs, and after 45 seconds it fires, alerts you that it has fired,
and adds a line of text to the web page, which appears when you type rr.
Try it and see; just browse and wait 45 seconds, then type rr.

But there's a more involved test that I've been running.
http://www.eklhad.net/async
It's a short file; I'll just include it here.

<html>
<head><title>Asynchronous Test </title></head>
<body>
Web page has been up for <span id=counter>0</span> seconds.
<script type=text/javascript>
var cnt = 0;
function increment() {
++cnt;
document.getElementById("counter").innerHTML = cnt;
}
setInterval("increment()", 1000);
</script>
</body>

The timer fires once a second and updates the count.
edbrowse async, and browse, and type rr, and see how long the web page has been up.
After this has run for a bit,
b bsync
assuming you have linked async to bsync, so the file has another name.
It's just another copy of the same file running.
But the timers in both copies continue to run,
the foreground and the background.
Type ^ to pop back to the original copy
and it has the right time.
Switch to session 2 and browse async and let it run.
You can switch between the 2 sessions and they show the right times.
Finally switch to session 3 and edit a letter to your friend.
Make various changes, and even undo a change.
Trust me, that was the hard part.
Timers are updating the text in other windows,
and those changes can't get in the way of the changes you are making,
or the ability to undo a change.
That required some redesign.
So not a lot of code changes but yet a lot of changes.
I had to push through a couple of seg faults,
and I hope there aren't more lurking in the wings.

The cool part is we can update the various trees in the various windows
asynchronously, and rerender, and apply the changes to the text buffers.

Karl Dahlke

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-18 19:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-18 19:46 [Edbrowse-dev] An Asynchronous Experiment Karl Dahlke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).