Javascript thread manager