FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DesignPatternsPHP/Creational/Pool/Processor.php at master · royopa/DesignPatternsPHP · GitHub
royopa
DesignPatternsPHP
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
DesignPatternsPHP
/
Creational
/
Pool
/
Processor.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (42 loc) · 1.06 KB
Breadcrumbs
DesignPatternsPHP
/
Creational
/
Pool
/
Processor.php
Copy path
File metadata and controls
52 lines (42 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
namespace
DesignPatterns
\
Creational
\
Pool
;
class
Processor
{
private
$
pool
;
private
$
processing
=
0
;
private
$
maxProcesses
=
3
;
private
$
waitingQueue
= [];
public
function
__construct
(
Pool
$
pool
)
{
$
this
->
pool
=
$
pool
;
}
public
function
process
(
$
image
)
{
if
(
$
this
->
processing
++ <
$
this
->
maxProcesses
) {
$
this
->
createWorker
(
$
image
);
}
else
{
$
this
->
pushToWaitingQueue
(
$
image
);
}
}
private
function
createWorker
(
$
image
)
{
$
worker
=
$
this
->
pool
->
get
();
$
worker
->
run
(
$
image
,
array
(
$
this
,
'
processDone
'
));
}
public
function
processDone
(
$
worker
)
{
$
this
->
processing
--;
$
this
->
pool
->
dispose
(
$
worker
);
if
(
count
(
$
this
->
waitingQueue
) >
0
) {
$
this
->
createWorker
(
$
this
->
popFromWaitingQueue
());
}
}
private
function
pushToWaitingQueue
(
$
image
)
{
$
this
->
waitingQueue
[] =
$
image
;
}
private
function
popFromWaitingQueue
()
{
return
array_pop
(
$
this
->
waitingQueue
);
}
}
Back
|
FazBrowse Home
|
New Git URL