Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tv_panel
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hermod
tv_panel
Commits
aac0dd5f
Commit
aac0dd5f
authored
7 years ago
by
Ayc0
Browse files
Options
Downloads
Patches
Plain Diff
feat: add start, startNow, restart, restartNow, stop in interval
parent
835203e4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
front/src/style.css
+2
-4
2 additions, 4 deletions
front/src/style.css
server/index.js
+1
-1
1 addition, 1 deletion
server/index.js
server/utils.js
+42
-20
42 additions, 20 deletions
server/utils.js
with
45 additions
and
25 deletions
front/src/style.css
+
2
−
4
View file @
aac0dd5f
...
...
@@ -55,10 +55,8 @@
justify-content
:
space-between
;
}
.image-text-bloc
>
.text-section
>
.text-element
:first-child
{
flex-grow
:
1
;
}
.image-text-bloc
>
.text-section
>
.text-element
:last-child
{
white-space
:
nowrap
;
flex-grow
:
1
;
text-align
:
right
;
}
This diff is collapsed.
Click to expand it.
server/index.js
+
1
−
1
View file @
aac0dd5f
...
...
@@ -41,6 +41,6 @@ io.of('/').on('connection', (socket) => {
});
socket
.
on
(
'
disconnect
'
,
()
=>
{
chrono
.
clear
();
chrono
.
stop
();
});
});
This diff is collapsed.
Click to expand it.
server/utils.js
+
42
−
20
View file @
aac0dd5f
...
...
@@ -2,14 +2,6 @@
const
jwt
=
require
(
'
jsonwebtoken
'
);
const
{
cert
}
=
require
(
'
./config
'
);
const
initialOutput
=
{
id
:
null
,
clear
:
()
=>
undefined
,
trigger
:
()
=>
undefined
};
const
replace
=
(
toReplace
,
replacer
)
=>
{
Object
.
keys
(
replacer
).
forEach
((
x
)
=>
{
toReplace
[
x
]
=
replacer
[
x
];
});
};
function
Timeout
(
fn
,
interval
)
{
this
.
id
=
setTimeout
(
fn
,
interval
);
this
.
cleared
=
false
;
...
...
@@ -19,7 +11,7 @@ function Timeout(fn, interval) {
};
}
const
interval
=
(
fn
,
initialTTL
,
output
=
initialOutput
)
=>
{
const
interval
=
(
fn
,
initialTTL
,
output
=
{}
)
=>
{
const
getTimeout
=
ttl
=>
new
Timeout
(
async
()
=>
{
let
TTL
;
...
...
@@ -41,18 +33,48 @@ const interval = (fn, initialTTL, output = initialOutput) => {
const
nextTTL
=
parseInt
(
TTL
,
10
)
||
initialTTL
;
interval
(
fn
,
nextTTL
,
output
);
},
ttl
);
const
getOutput
=
timeout
=>
({
id
:
timeout
.
id
,
c
lear
:
()
=>
timeout
.
clear
(),
trigger
:
()
=>
{
const
getOutput
=
(
timeout
)
=>
{
c
onst
stop
=
()
=>
{
if
(
timeout
)
{
timeout
.
clear
();
const
newTimeout
=
getTimeout
(
0
);
replace
(
output
,
getOutput
(
newTimeout
));
}
};
return
{
start
:
(
ttl
)
=>
{
if
(
timeout
&&
!
timeout
.
cleared
)
{
throw
new
Error
(
'
Interval is already started
'
);
}
const
newOutput
=
getOutput
(
getTimeout
(
ttl
||
initialTTL
));
Object
.
assign
(
output
,
getOutput
(
newOutput
));
return
output
;
},
startNow
:
()
=>
{
if
(
timeout
&&
!
timeout
.
cleared
)
{
throw
new
Error
(
'
Interval is already started
'
);
}
Object
.
assign
(
output
,
getOutput
(
getTimeout
(
0
)));
return
output
;
},
});
restart
:
(
ttl
)
=>
{
stop
();
Object
.
assign
(
output
,
getOutput
(
getTimeout
(
ttl
||
initialTTL
)));
return
output
;
},
stop
,
restartNow
:
()
=>
{
stop
();
Object
.
assign
(
output
,
getOutput
(
getTimeout
(
0
)));
return
output
;
},
};
};
const
timeout
=
getTimeout
(
initialTTL
);
replace
(
output
,
getOutput
(
timeout
));
if
(
Object
.
keys
(
output
).
length
===
0
)
{
Object
.
assign
(
output
,
getOutput
(
null
));
}
else
{
Object
.
assign
(
output
,
getOutput
(
getTimeout
(
initialTTL
)));
}
return
output
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment