Example #1
0
        static void Main(string[] args)
        {
            var promise = new Promise(() =>
            {
                //This is syncronous, blocking code
                var request = WebRequest.Create("https://spiderserver.herokuapp.com");
                var response = request.GetResponse().GetResponseStream();
                var reader = new StreamReader(response);
                var html = reader.ReadToEnd();
                Console.WriteLine(html);
            });

            promise.Then(() =>
            {
                Console.WriteLine("Promise has resolved");
            });

            //Down here we'll count up for a bit

            var countTo = 40;

            for (var i = 0; i < countTo; i++)
            {
                Console.WriteLine(i.ToString());
                Thread.Sleep(100);
            }
        }
Example #2
0
 public Promise(Promise previousPromise)
 {
     PreviousPromise = previousPromise;
     Task.Run(() => 
     {
         while (PreviousPromise.Resolved == false)
         {
             Thread.Sleep(10);
         }
         if (OnResolved != null)
         {
             Resolve();
         }
     });
 }