Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
19e551c7
Unverified
Commit
19e551c7
authored
Oct 29, 2019
by
Jonah Williams
Committed by
GitHub
Oct 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Poller class from flutter_tools (#43685)
parent
ea4da39f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
105 deletions
+17
-105
utils.dart
packages/flutter_tools/lib/src/base/utils.dart
+0
-40
device.dart
packages/flutter_tools/lib/src/device.dart
+17
-13
utils_test.dart
packages/flutter_tools/test/general.shard/utils_test.dart
+0
-52
No files found.
packages/flutter_tools/lib/src/base/utils.dart
View file @
19e551c7
...
@@ -8,7 +8,6 @@ import 'dart:math' show Random, max;
...
@@ -8,7 +8,6 @@ import 'dart:math' show Random, max;
import
'package:intl/intl.dart'
;
import
'package:intl/intl.dart'
;
import
'../convert.dart'
;
import
'../convert.dart'
;
import
'../globals.dart'
;
import
'context.dart'
;
import
'context.dart'
;
import
'file_system.dart'
;
import
'file_system.dart'
;
import
'io.dart'
as
io
;
import
'io.dart'
as
io
;
...
@@ -258,45 +257,6 @@ Map<String, dynamic> castStringKeyedMap(dynamic untyped) {
...
@@ -258,45 +257,6 @@ Map<String, dynamic> castStringKeyedMap(dynamic untyped) {
typedef
AsyncCallback
=
Future
<
void
>
Function
();
typedef
AsyncCallback
=
Future
<
void
>
Function
();
/// A [Timer] inspired class that:
/// - has a different initial value for the first callback delay
/// - waits for a callback to be complete before it starts the next timer
class
Poller
{
Poller
(
this
.
callback
,
this
.
pollingInterval
,
{
this
.
initialDelay
=
Duration
.
zero
})
{
Future
<
void
>.
delayed
(
initialDelay
,
_handleCallback
);
}
final
AsyncCallback
callback
;
final
Duration
initialDelay
;
final
Duration
pollingInterval
;
bool
_canceled
=
false
;
Timer
_timer
;
Future
<
void
>
_handleCallback
()
async
{
if
(
_canceled
)
{
return
;
}
try
{
await
callback
();
}
catch
(
error
)
{
printTrace
(
'Error from poller:
$error
'
);
}
if
(!
_canceled
)
{
_timer
=
Timer
(
pollingInterval
,
_handleCallback
);
}
}
/// Cancels the poller.
void
cancel
()
{
_canceled
=
true
;
_timer
?.
cancel
();
_timer
=
null
;
}
}
/// Returns a [Future] that completes when all given [Future]s complete.
/// Returns a [Future] that completes when all given [Future]s complete.
///
///
/// Uses [Future.wait] but removes null elements from the provided
/// Uses [Future.wait] but removes null elements from the provided
...
...
packages/flutter_tools/lib/src/device.dart
View file @
19e551c7
...
@@ -251,28 +251,32 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
...
@@ -251,28 +251,32 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
final
String
name
;
final
String
name
;
ItemListNotifier
<
Device
>
_items
;
ItemListNotifier
<
Device
>
_items
;
Poller
_poll
er
;
Timer
_tim
er
;
Future
<
List
<
Device
>>
pollingGetDevices
();
Future
<
List
<
Device
>>
pollingGetDevices
();
void
startPolling
()
{
void
startPolling
()
{
if
(
_
poll
er
==
null
)
{
if
(
_
tim
er
==
null
)
{
_items
??=
ItemListNotifier
<
Device
>();
_items
??=
ItemListNotifier
<
Device
>();
_timer
=
_initTimer
();
_poller
=
Poller
(()
async
{
try
{
final
List
<
Device
>
devices
=
await
pollingGetDevices
().
timeout
(
_pollingTimeout
);
_items
.
updateWithNewList
(
devices
);
}
on
TimeoutException
{
printTrace
(
'Device poll timed out. Will retry.'
);
}
},
_pollingInterval
);
}
}
}
}
Timer
_initTimer
()
{
return
Timer
(
_pollingInterval
,
()
async
{
try
{
final
List
<
Device
>
devices
=
await
pollingGetDevices
().
timeout
(
_pollingTimeout
);
_items
.
updateWithNewList
(
devices
);
}
on
TimeoutException
{
printTrace
(
'Device poll timed out. Will retry.'
);
}
_timer
=
_initTimer
();
});
}
void
stopPolling
()
{
void
stopPolling
()
{
_
poll
er
?.
cancel
();
_
tim
er
?.
cancel
();
_
poll
er
=
null
;
_
tim
er
=
null
;
}
}
@override
@override
...
...
packages/flutter_tools/test/general.shard/utils_test.dart
View file @
19e551c7
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:async'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/utils.dart'
;
import
'package:flutter_tools/src/base/utils.dart'
;
import
'package:flutter_tools/src/base/version.dart'
;
import
'package:flutter_tools/src/base/version.dart'
;
...
@@ -122,56 +120,6 @@ baz=qux
...
@@ -122,56 +120,6 @@ baz=qux
});
});
});
});
group
(
'Poller'
,
()
{
const
Duration
kShortDelay
=
Duration
(
milliseconds:
100
);
Poller
poller
;
tearDown
(()
{
poller
?.
cancel
();
});
test
(
'fires at start'
,
()
async
{
bool
called
=
false
;
poller
=
Poller
(()
async
{
called
=
true
;
},
const
Duration
(
seconds:
1
));
expect
(
called
,
false
);
await
Future
<
void
>.
delayed
(
kShortDelay
);
expect
(
called
,
true
);
});
test
(
'runs periodically'
,
()
async
{
// Ensure we get the first (no-delay) callback, and one of the periodic callbacks.
int
callCount
=
0
;
poller
=
Poller
(()
async
{
callCount
++;
},
Duration
(
milliseconds:
kShortDelay
.
inMilliseconds
~/
2
));
expect
(
callCount
,
0
);
await
Future
<
void
>.
delayed
(
kShortDelay
);
expect
(
callCount
,
greaterThanOrEqualTo
(
2
));
});
test
(
'no quicker then the periodic delay'
,
()
async
{
// Make sure that the poller polls at delay + the time it took to run the callback.
final
Completer
<
Duration
>
completer
=
Completer
<
Duration
>();
DateTime
firstTime
;
poller
=
Poller
(()
async
{
if
(
firstTime
==
null
)
{
firstTime
=
DateTime
.
now
();
}
else
{
completer
.
complete
(
DateTime
.
now
().
difference
(
firstTime
));
}
// introduce a delay
await
Future
<
void
>.
delayed
(
kShortDelay
);
},
kShortDelay
);
final
Duration
duration
=
await
completer
.
future
;
expect
(
duration
,
greaterThanOrEqualTo
(
Duration
(
milliseconds:
kShortDelay
.
inMilliseconds
*
2
)));
});
});
group
(
'Misc'
,
()
{
group
(
'Misc'
,
()
{
test
(
'snakeCase'
,
()
async
{
test
(
'snakeCase'
,
()
async
{
expect
(
snakeCase
(
'abc'
),
equals
(
'abc'
));
expect
(
snakeCase
(
'abc'
),
equals
(
'abc'
));
...
...
Write
Preview
Markdown
is supported
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