Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
SemWeb
libview
Commits
91536d03bc1b
Commit
428f04ef
authored
Dec 21, 2018
by
Laurent Wouters
Browse files
[fix] Support adding timeout to promises
parent
fa40a82c3a83
Changes
1
Hide whitespace changes
Inline
Side-by-side
libview/src/application.ts
View file @
91536d03
...
...
@@ -185,7 +185,7 @@ export function probeResourceWith(
}
};
resource
.
uris
.
forEach
((
uri
:
string
)
=>
probeResourceUri
(
uri
)
withTimeout
(
probe
(
uri
),
250
)
.
then
((
uri
:
string
)
=>
{
remaining
.
push
(
uri
);
onFinished
();
...
...
@@ -196,6 +196,35 @@ export function probeResourceWith(
);
}
/**
* Wraps a promise in a new one with a timeout
* @param original The original promise
* @param wait The time to wait
*/
export
function
withTimeout
<
T
>
(
original
:
Promise
<
T
>
,
wait
:
number
):
Promise
<
T
>
{
return
new
Promise
<
T
>
(
(
resolve
:
(
result
:
T
)
=>
void
,
reject
:
(
reason
:
any
)
=>
void
)
=>
{
let
timeoutTriggered
=
false
;
let
onTimeout
=
()
=>
{
timeoutTriggered
=
true
;
reject
(
"
timeout
"
);
};
let
handle
=
setTimeout
(
onTimeout
,
wait
);
original
.
then
((
result
:
T
)
=>
{
if
(
timeoutTriggered
)
return
;
clearTimeout
(
handle
);
resolve
(
result
);
})
.
catch
((
reason
:
any
)
=>
{
if
(
timeoutTriggered
)
return
;
clearTimeout
(
handle
);
reject
(
reason
);
});
}
);
}
/**
* Probes an URI for a resource to check whether it is valid
* @param uri An URI
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment