Quantcast
Channel: よーめー日記
Viewing all articles
Browse latest Browse all 223

JavcaScriptでsleep関数を作る

$
0
0
JavaScriptでsleep関数を使いたくなる時があります。
残念ながら、多くのサイトにはsleep関数はないと書いてあります。

でも、そんなときはConcurrentThread.jsがお勧めです。
http://sourceforge.jp/projects/sfnet_jsthread/releases/


関数をコンパイルする関数を呼び出さないといけないのですが、このように簡単にスリープできます。
C言語風に書いてみました。
スリープだけでなく、スレッドも作れます。


---------------
function print(str)
{
    $("#body").append(str+"<br/>");
}

function mysleep(ms)
{
    Concurrent.Thread.sleep(ms);
}
mysleep=Concurrent.Thread.compile(mysleep);


function main()
{
    print("Hello Javascript World!!");
    mysleep(1000);
    print("Hello Javascript World!!");
}
main=Concurrent.Thread.compile(main);


$(function(){
    Concurrent.Thread.create(main);
});



Viewing all articles
Browse latest Browse all 223

Trending Articles