-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcurrently
69 lines (59 loc) · 1.54 KB
/
concurrently
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env php
<?php
/**
* Library .bin file
* primary executable script file $ concurrently [options] [arguments]
*
* @author Lochemem Bruno Michael
* @license Apache-2.0
*/
foreach (
[
__DIR__ . '/../autoload.php',
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../vendor/autoload.php',
] as $file
) {
if (\file_exists($file)) {
\define('AUTOLOAD_PHP_FILE', $file);
break;
}
}
if (!\defined('AUTOLOAD_PHP_FILE')) {
\fwrite(STDERR,
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'wget http://getcomposer.org/composer.phar' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
die(1);
}
require AUTOLOAD_PHP_FILE;
use React\EventLoop\Factory;
use Rx\Scheduler;
use Chemem\{
Concurrently\Console as c,
Bingo\Functional as f,
Bingo\Functional\Functors\Monads\IO,
};
// terminate process if it is running outside a console environment
if (PHP_SAPI !== 'cli') {
IO\putStr('Sorry, php-concurrently only runs in a console environment')
->map(function ($_) {
exit();
})
->exec();
}
// set general exception handler
\set_exception_handler(function ($_) {
return IO\putStr('Sorry, an error occurred')->exec();
});
// convert script arguments to parsable string
$args = \implode(' ', f\dropLeft($argv, 1));
$loop = Factory::create();
Scheduler::setDefaultFactory(function () use ($loop) {
return new Scheduler\EventLoopScheduler($loop);
});
$console = c\parse($loop, $args)->exec();
$loop->run();