diff options
author | Matth?us G. Chajdas <dev@anteru.net> | 2019-11-10 13:56:53 +0100 |
---|---|---|
committer | Matth?us G. Chajdas <dev@anteru.net> | 2019-11-10 13:56:53 +0100 |
commit | 1dd3124a9770e11b6684e5dd1e6bc15a0aa3bc67 (patch) | |
tree | 87a171383266dd1f64196589af081bc2f8e497c3 /tests/examplefiles/example.kal | |
parent | f1c080e184dc1bbc36eaa7cd729ff3a499de568a (diff) | |
download | pygments-master.tar.gz |
Diffstat (limited to 'tests/examplefiles/example.kal')
-rw-r--r-- | tests/examplefiles/example.kal | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/tests/examplefiles/example.kal b/tests/examplefiles/example.kal deleted file mode 100644 index c05c14ca..00000000 --- a/tests/examplefiles/example.kal +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env kal - -# This demo executes GET requests in parallel and in series -# using `for` loops and `wait for` statements. - -# Notice how the serial GET requests always return in order -# and take longer in total. Parallel requests come back in -# order of receipt. - -http = require 'http' - -urls = ['http://www.google.com' - 'http://www.apple.com' - 'http://www.microsoft.com' - 'http://www.nodejs.org' - 'http://www.yahoo.com'] - -# This function does a GET request for each URL in series -# It will wait for a response from each request before moving on -# to the next request. Notice the output will be in the same order as the -# urls variable every time regardless of response time. -# It is a task rather than a function because it is called asynchronously -# This allows us to use `return` to implicitly call back -task series_demo() - # The `series` keyword is optional here (for loops are serial by default) - total_time = 0 - - for series url in urls - timer = new Date - - # we use the `safe` keyword because get is a "nonstandard" task - # that does not call back with an error argument - safe wait for response from http.get url - - delay = new Date() - timer - total_time += delay - - print "GET #{url} - #{response.statusCode} - #{response.connection.bytesRead} bytes - #{delay} ms" - - # because we are in a task rather than a function, this actually exectutes a callback - return total_time - -# This function does a GET request for each URL in parallel -# It will NOT wait for a response from each request before moving on -# to the next request. Notice the output will be determined by the order in which -# the requests complete! -task parallel_demo() - total_time = 0 - - # The `parallel` keyword is only meaningful here because the loop contains - # a `wait for` statement (meaning callbacks are used) - for parallel url in urls - timer = new Date - - # we use the `safe` keyword because get is a "nonstandard" task - # that does not call back with an error argument - safe wait for response from http.get url - - delay = new Date() - timer - total_time += delay - - print "GET #{url} - #{response.statusCode} - #{response.connection.bytesRead} bytes - #{delay}ms" - - # because we are in a task rather than a function, this actually exectutes a callback - return total_time - -print 'Series Requests...' -wait for time1 from series_demo() -print "Total duration #{time1}ms" - -print '' - -print 'Parallel Requests...' -wait for time2 from parallel_demo() -print "Total duration #{time2}ms" |