Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
4f492058
Commit
4f492058
authored
1 year ago
by
Egor Ivkov
Committed by
Егор Ивков
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add sleep_async fn
parent
3ff98fcc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!601
refactor: improve join/update instance with cas
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/util.rs
+18
-0
18 additions, 0 deletions
src/util.rs
with
18 additions
and
0 deletions
src/util.rs
+
18
−
0
View file @
4f492058
...
...
@@ -3,6 +3,8 @@ use std::io::BufRead as _;
use
std
::
io
::
BufReader
;
use
std
::
io
::
Write
as
_
;
use
std
::
os
::
unix
::
io
::
AsRawFd
as
_
;
use
tarantool
::
fiber
;
use
tarantool
::
fiber
::
r
#
async
::
timeout
::
IntoTimeout
;
pub
use
Either
::{
Left
,
Right
};
use
crate
::
traft
::
error
::
Error
;
...
...
@@ -12,11 +14,18 @@ use std::time::{Duration, Instant};
const
INFINITY
:
Duration
=
Duration
::
from_secs
(
30
*
365
*
24
*
60
*
60
);
// TODO: move to tarantool_module when we have custom `Instance` there
pub
fn
instant_saturating_add
(
t
:
Instant
,
d
:
Duration
)
->
Instant
{
t
.checked_add
(
d
)
.unwrap_or_else
(||
t
.checked_add
(
INFINITY
)
.expect
(
"that's too much, man"
))
}
// TODO: move to tarantool_module
pub
async
fn
sleep_async
(
time
:
Duration
)
{
let
(
_
,
rx
)
=
fiber
::
r
#
async
::
oneshot
::
channel
::
<
()
>
();
rx
.timeout
(
time
)
.await
.unwrap_err
();
}
////////////////////////////////////////////////////////////////////////////////
/// A generic enum that contains exactly one of two possible types. Equivalent
/// to `std::result::Result`, but is more intuitive in some cases.
...
...
@@ -552,3 +561,12 @@ mod tests {
);
}
}
mod
tarantool_tests
{
use
std
::
time
::
Duration
;
#[::tarantool::test]
async
fn
sleep_wakes_up
()
{
super
::
sleep_async
(
Duration
::
from_millis
(
10
))
.await
;
}
}
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