Friday, November 24, 2006

Java Script multi-threading

We all know that it is not possible,...but... using timers along with path-through routines that don't block might sound like a cool alternative. I have tried it and it works - picture this:

function doLongTask(x,y,z, callback)
{
this.X = x;
this.Y = y;
this.Z = z;
this.doneCallback=callback;
}

doLongTask.prototype.threadSpin = _longtask_threadspin;

function _longtask_threadspin()
{
//instead of long loops save your intermediate state in this.{vars}

this.X++;
if (this.X%100==0) this.Z = this.Y - 100; //some logic that would have been in a tight loop

if (this.X>1000) this.doneCallback();

}


And now we can easily:

var task = new doLongTask(1,2,3,doneLongTask);
var tmr = setInterval(task.threadSpin, 10/*time slice!!!*/);

function doneLongTask()
{
task.Z // result of task
clearInterval(tmr);// kill 'thread'
}

24 comments:

Anonymous said...

COOL, this should be ok - no closures problems either

itAdapter said...

Yes, speaking of closures I am trying to avoid this pattern:
this.X = function(){.....}
as much as I can because
eventually this will crash IE

Anonymous said...

helped, thanks

Anonymous said...

such a waste

Anonymous said...

I heard Chrome v8 compiles js to bin maybe those guys give access to real thing threads _xeh_

Anonymous said...

I'm newbie here, I hope to get friends at this forum

Coach Factory said...

louboutin outlet, michael kors handbags clearance, air jordan, oakley vault, burberry outlet online, kate spade handbags, louis vuitton handbags, michael kors outlet online, ray ban sunglasses, cheap oakley sunglasses, michael kors outlet online, toms shoes, prada outlet, true religion outlet, jordan shoes, coach purses, longchamp handbags, michael kors outlet, polo ralph lauren outlet online, coach outlet store online, nike free, tiffany and co, polo ralph lauren outlet, prada handbags, oakley sunglasses, nike air max, longchamp handbags, true religion, nike free, kate spade outlet, nike shoes, tory burch outlet, nike air max, louis vuitton outlet online, coach outlet, coach factory outlet, true religion jeans, ray ban sunglasses outlet, air max, longchamp outlet, air max, gucci outlet, louboutin, cheap michael kors, chanel handbags

Coach Factory said...

lululemon outlet, ray ban, nike roshe, mont blanc, converse shoes, karen millen, michael kors, roshe run, nfl jerseys, nike huarache, birkin bag, beats by dre, mac cosmetics, hogan, louboutin, converse pas cher, ray ban pas cher, montre pas cher, michael kors, vans, north face jackets, lululemon, oakley pas cher, north face outlet, reebok outlet, michael kors, nike free, ralph lauren, nike trainers, louis vuitton, louis vuitton, hollister, hermes, timberland, abercrombie and fitch, supra shoes, new balance shoes, juicy couture outlet, mulberry, air max, lancel, hollister, north face, rolex watches, juicy couture outlet, burberry, wedding dresses, new balance pas cher, abercrombie and fitch, nike air max

Coach Factory said...

nike air max, air max pas cher, p90x3, converse, ugg boots, ferragamo shoes, giuseppe zanotti, louboutin, moncler, mcm handbags, air max pas cher, ralph lauren, ugg outlet, soccer jerseys, valentino shoes, herve leger, babyliss pro, moncler, moncler, jimmy choo, vans, asics gel, air max, moncler outlet, chi flat iron, canada goose outlet, uggs on sale, hollister, canada goose, instyler ionic styler, moncler, canada goose, insanity, marc jacobs, tn pas cher, ray ban, canada goose outlet, air max, soccer shoes, canada goose, bottega veneta, ghd, ugg, celine handbags, ugg, gucci, canada goose, ugg boots, oakley

mao qiuyun said...

chanel handbags, http://www.chanelhandbags-outlet.co.uk/
the north face jackets, http://www.thenorthfacejacket.us.com/
canada goose outlet, http://www.canadagoose.us.org/
the north face outlet store, http://www.thenorthfaceoutletstores.org/
ugg boots, http://www.uggboot.com.co/
oakley sunglasses, http://www.oakleysunglasses-outlet.us.com/
hermes bags, http://www.hermesbags.co.uk/
oakley sunglasses, http://www.oakleysunglasseswholesale.in.net/
vans shoes, http://www.vans-shoes.cc/
coach outlet store, http://www.coach-outlet-store.us.com/
coach outlet canada, http://www.coachoutletcanada.com.co/
coach outlet, http://www.coachoutletstoreonline.in.net/
the north face uk, http://www.thenorthfaces.org.uk/
nike air max uk, http://www.nikeairmaxshoes.org.uk/
ray ban sunglasses, http://www.raybansunglass.us.com/
kobe shoes, http://www.kobeshoes.us/
nike free, http://www.nikefreerunning.org/
tory burch outlet, http://www.toryburchoutletonline.in.net/
ugg boots, http://www.uggbootscheap.eu.com/
designer handbags, http://www.designerhandbags.us.com/
cheap wedding dresses, http://www.cheap-weddingdresses.net/
michael kors outlet, http://www.michaelkorsoutletonlinestores.us.com/
air jordan 4, http://www.airjordan4.org/
fitflop, http://www.fitflop.in.net/
the north face outlet, http://www.northface-outlet.cc/
soccer jerseys, http://www.soccerjerseys.us.com/
air max 90, http://www.airmax90.us.com/
swarovski jewelry, http://www.swarovski.in.net/
ralph lauren uk, http://www.ralphlauren-outletonline.co.uk/
1006maoqiuyun

oakleyses said...

kate spade outlet online, nike air max, tory burch outlet online, ugg boots clearance, prada handbags, nike air max, ray ban sunglasses, michael kors handbags, chanel handbags, jordan shoes, nike outlet, longchamp outlet online, gucci handbags, christian louboutin, christian louboutin shoes, burberry outlet online, ugg outlet, oakley sunglasses, louis vuitton outlet, ray ban outlet, nike free, cheap oakley sunglasses, cheap ugg boots outlet, louis vuitton, longchamp outlet, michael kors outlet online, polo ralph lauren outlet, burberry outlet online, christian louboutin outlet, michael kors outlet online, oakley sunglasses, ray ban sunglasses, oakley vault, ugg australia, cheap ugg boots, red bottom shoes, replica watches, michael kors outlet, tiffany and co, tiffany jewelry, louis vuitton outlet online, replica watches, polo ralph lauren, prada outlet, louis vuitton handbags

oakleyses said...

guess pas cher, nike air max, nike roshe run, mulberry uk, coach outlet, true religion outlet, true religion outlet, new balance pas cher, abercrombie and fitch, longchamp, nike air max, scarpe hogan, air max pas cher, sac vanessa bruno, ray ban pas cher, nike roshe, north face, coach purses, burberry pas cher, nike free pas cher, lacoste pas cher, timberland pas cher, coach outlet, michael kors uk, michael kors, nike free, longchamp pas cher, tn pas cher, hollister uk, vans pas cher, true religion jeans, ray ban uk, true religion, michael kors outlet online, north face pas cher, hermes pas cher, air jordan, lululemon outlet online, hollister, michael kors canada, louboutin, nike blazer pas cher, kate spade outlet, coach outlet store online, oakley pas cher, converse pas cher, nike air force, ralph lauren uk, air max, ralph lauren pas cher

oakleyses said...

nike air max, longchamp, new balance outlet, oakley, mcm handbags, nike roshe, ferragamo shoes, nfl jerseys, asics shoes, ralph lauren, celine handbags, mont blanc pens, hollister, s6 cases, baseball bats, soccer jerseys, nike air huarache, p90x workout, hollister clothing store, bottega veneta, giuseppe zanotti, insanity workout, abercrombie and fitch, ghd, iphone cases, valentino shoes, mac cosmetics, herve leger, iphone 6 cases, iphone 5s cases, lululemon outlet, instyler ionic styler, north face jackets, vans outlet, wedding dresses, soccer shoes, north face jackets, jimmy choo shoes, iphone 6s plus cases, birkin bag, beats headphones, timberland boots, nike trainers, iphone 6 plus cases, louboutin, reebok shoes, babyliss, chi flat iron

oakleyses said...

pandora jewelry, swarovski uk, canada goose, moncler outlet, links of london uk, coach outlet, ugg boots, hollister canada, sac lancel, marc jacobs handbags, air max, pandora jewelry, converse, replica watches, vans, wedding dress, uggs outlet, canada goose pas cher, canada goose, uggs canada, louis vuitton uk, moncler, barbour, gucci, supra shoes, moncler outlet, canada goose, canada goose outlet, doke gabbana outlet, moncler, juicy couture outlet, sac louis vuitton, canada goose, canada goose outlet, montre femme, thomas sabo uk, ugg soldes, louis vuitton, louis vuitton pas cher, moncler, swarovski jewelry, michael kors outlet online, louis vuitton canada, barbour jackets, converse shoes, ugg, canada goose outlet, ugg, ray ban, karen millen, moncler

mmjiaxin said...

ferragamo shoes
michael kors outlet
rolex watches outlet
tory burch outlet online
michael kors handbags
coach outlet store
mac cosmetics
michael kors outlet online
wellensteyn outlet
michael kors outlet
canada goose outelt
air max 2014
ray ban,rayban,occhiali ray ban,ray-ban,ray ban occhiali,ray ban sunglasses
woolrich outlet store
fred perry polo shirts
michael kors outlet
tiffany outlet
canada goose jackets
oakley outlet store
mizuno running shoes
mm1202

方松腾 said...

ugg boots
cheap oakley sunglasses
true religion sale
air jordan 11 free shipping
toms outlet
louis vuitton outlet
michael kors outlet,michael kors outlet online,michael kors,kors outlet,michael kors handbags,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors
north face jackets
ferragamo shoes
soccer jerseys,soccer jerseys wholesale,soccer jerseys cheap,soccer jerseys for sale,cheap soccer jersey,usa soccer jersey,football jerseys
ugg boots on sale
vans sneakers
oakley sunglasses
fitflops outlet
coach outlet online,coach purses,coach handbags,coach bags,coach handbags sale,coach handbags outlet

方松腾 said...

ugg boots
cheap oakley sunglasses
true religion sale
air jordan 11 free shipping
toms outlet
louis vuitton outlet
michael kors outlet,michael kors outlet online,michael kors,kors outlet,michael kors handbags,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors
north face jackets
ferragamo shoes
soccer jerseys,soccer jerseys wholesale,soccer jerseys cheap,soccer jerseys for sale,cheap soccer jersey,usa soccer jersey,football jerseys
ugg boots on sale
vans sneakers
oakley sunglasses
fitflops outlet
coach outlet online,coach purses,coach handbags,coach bags,coach handbags sale,coach handbags outlet

chenlili said...

michael kors outlet clearance
adidas shoes
ray ban sunglasses
hermes handbags
ugg outlet store
cheap jordans
ugg boots paris
uggs outlet
rolex watches
coach factory outlet
louboutin shoes
michael kors outlet online
louis vuitton outlet
ugg canada
polo ralph kids
michael kors outlet online
moncler jackets
timberlands
louis vuitton handbags
louis vuitton handbags
nhl jerseys
coach outlet store online clearances
louboutin femme
christian louboutin shoes
christian louboutin sale
louis vuitton outlet
gucci outlet online
ralph lauren outlet
coach factory outlet
michael kors handbags
uggs
ray ban sunglasses
hollister clothing
christian louboutin outlet
ray ban sunglasses
cheap oakleys
fitflops shoes
michael kors outlet
chenlili20160829

Unknown said...

michael kors handbags sale
ralph lauren pas cher
cheap oakley sunglasses
golden state warriors
michael kors handbags
miami dolphins jerseys
converse shoes
adidas nmd r1
new york knicks
jordan shoes

Unknown said...

ravens jerseys
michael kors handbags
hermes belt
fitflops shoes
abercrombie and fitch
michael kors outlet store
michael kors handbags
nike air huarache
bears jerseys
michael kors handbags

GIL BERT said...

nike blazer
jimmy choo
coach outlet
longchamp handbags
asics shoes
air jordan 4
redskins jerseys
coach handbags
longchamp outlet
nike air huarache

John said...

coach outlet online
tods outlet
columbia outlet
nike air max 95
coach outlet online
pandora jewelry store
coach handbags outlet
coach factory outlet online
kate spade outlet online
nike air max
20170704yuanyuan

qqq said...

michael kors outlet store
jimmy choo
kate spade handbags
yeezy boost
pandora jewelry
ultra boost
pandora jewelry
louboutin chaussures
under armour shoes
coach factory outlet
170810yueqin

Games 2 Girls said...

It is a great article. You will surely like this also because it is a great stufff
instagram viewer images