Last active
August 29, 2015 14:07
-
-
Save iwankgb/2e8b81b9ccc52e0633c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh //strict | |
function main(): int { | |
//array_shift($args); | |
//var_dump($args); | |
/*$input = Vector{}; | |
foreach ($args->items() as $url) { | |
$input->add(fetch_url($url)); | |
}*/ | |
//var_dump($input); | |
$strings = GenVectorWaitHandle::create(Vector { | |
//fetch_url('http://www.bbc.com/news/world-asia-27096629 http://www.bbc.com/future/story/20140418-the-top-attenborough-moments'), | |
random_seal(), | |
//fetch_url('http://www.bbc.com/news/world-europe-27124453 http://www.bbc.com/news/world-middle-east-27128902'), | |
random_seal(), | |
//fetch_url('http://www.bbc.co.uk/news/world-middle-east-27186339'), | |
random_seal(), | |
//fetch_url('http://www.bbc.co.uk/sport/football/27194672 http://www.bbc.co.uk/news/entertainment-arts-27194863'), | |
random_seal(), | |
//fetch_url('http://www.bbc.co.uk/news/entertainment-arts-27186593 http://www.bbc.co.uk/news/technology-27187615'), | |
random_seal(), | |
//fetch_url('http://www.bbc.com/autos/story/20140428-what-your-car-says-about-you'), | |
random_seal(), | |
//fetch_url('http://localhost:8888/sleep.php'), | |
//fetch_url('http://localhost:8888/sleep.php'), | |
//fetch_url('http://localhost:8888/sleep.php'), | |
//fetch_url('http://localhost:8888/sleep.php'), | |
//fetch_url('http://localhost:8888/sleep.php'), | |
//fetch_url('http://localhost:8888/sleep.php') | |
}); | |
while (!$strings->isFinished()) {} | |
$mamo = $strings->join(); | |
foreach ($mamo as $wtf) { | |
var_dump($wtf); | |
} | |
var_dump($strings); | |
//return $strings; | |
return 0; | |
} | |
async function random_seal(): Awaitable <FetchResult> | |
{ | |
$start = microtime(true); | |
$rand = mt_rand(2000000000, 2147483647); | |
//await RescheduleWaitHandle::create(1,1); | |
$end = microtime(true); | |
echo "$start\t$end\n"; | |
return new FetchResult('to jest liczba losowa: ' . $rand, $start, $end); | |
} | |
async function fetch_url(string $url): Awaitable <FetchResult> | |
{ | |
$start = microtime(true); | |
echo "start: $start\n"; | |
file_get_contents($url); | |
//$rand = mt_rand(1000000000, 2147483647); | |
$rand = 0; | |
$end = microtime(true); | |
echo "end: $end\n"; | |
return new FetchResult('to jest liczba losowa: ' . $rand, $start, $end); | |
} | |
class FetchResult | |
{ | |
public function __construct(private string $return, private float $start, private float $end) {} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment