Skip to content

skeeto/thread-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

User Space JavaScript Threads

See the article: Userspace Threading in JavaScript

This is experimental. I don't yet know how practical it would be in a real application.

/* Recursively fetch status string in a thread. */
function updateStatus() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', '/status', true);  // long poll
    xhr.send();
    xhr.onload = Thread.wrap(function() {
        document.getElementById('status').innerHTML = xhr.responseText;
        Thread.yield(updateStatus);
    });
};

/* Start a thread to handle status updates. */
var statusThread = new Thread(updateStatus);

/* Stop and start the thread at will. */
statusThread.stop();
// ...
statusThread.start();

About

User space JavaScript threads

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published