Sunday, October 7, 2007

Boo - Asynchronous call

import System
import System.Collections
import System.Threading
import System.Net

def callback(result as IAsyncResult):
    print("callback")
    
def run():
    print "Executing"
    
print("started")

result = run.BeginInvoke(callback, null)
System.Threading.Thread.Sleep(50ms)
run.EndInvoke(result)

print ("done")

request = WebRequest.Create("http://www.python.org/")

result = request.GetResponse.BeginInvoke(null, null)
while not result.IsCompleted:
    Console.Write("!")
    Thread.Sleep(25ms)
Console.WriteLine()

// ready to get the response
response = request.GetResponse.EndInvoke(result)

Console.WriteLine("${response.ContentLength} bytes.")

print "Press any key to continue . . . "
Console.ReadKey(true)

No comments:

Post a Comment