Sha256: 0bf73b498edf44f6509c2cb5b1dead7838277c0c9fa0eb3a3dc91e3b45725d78
Contents?: true
Size: 864 Bytes
Versions: 1
Compression:
Stored size: 864 Bytes
Contents
def async curl: url { out = System pipe: "curl #{url}" return out read # return string of html } def async curl_urls: urls { results = [] urls each: |url| { # await means it will suspend the current context until the curl: has finished # and will resume with the line below data = await curl: url results << data } return results } URLS = ["http://www.backtype.com", "http://www.fancy-lang.org", "http://tech.backtype.com"] # usage (runs it asynchronously and returns a future that will hold the data when its done) f = curl_urls: URLS # do something else... # then after some time access the data: f value each: |html| { html println } # or hook it up with something to do when its done: curl_urls: URLS && |data| { data each: |html| { html println } } # shorter version of above: curl_urls: URLS && @{each: 'println}
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fancy-0.3.3 | examples/curl_async.fy |