1
+ import 'dart:async' ;
1
2
import 'dart:convert' ;
2
3
import 'dart:core' ;
3
4
@@ -16,22 +17,26 @@ Future<Schedule> postSchedule(Schedule schedule) async {
16
17
final uri = Uri .http (apiUrl, '$scheduleEndpoint ' );
17
18
final response = await httpClient.put (uri,
18
19
headers: applicationJsonHeader,
19
- body: jsonEncode (serialize <Schedule >(schedule)));
20
+ body: jsonEncode (serialize <Schedule >(schedule))). timeout (timeout) ;
20
21
_expectResponseCode (201 , response);
21
22
return deserialize <Schedule >(jsonDecode (response.body));
22
23
}
23
24
24
25
Future <List <Schedule >> getSchedules () async {
25
26
final uri = Uri .http (apiUrl, scheduleEndpoint);
26
- final response = await httpClient.get (uri);
27
- _expectResponseCode (200 , response);
28
- // Use the compute function to run parseSchedules in a separate isolate.
29
- return compute (_parseSchedules, response.body);
27
+ try {
28
+ final response = await httpClient.get (uri).timeout (timeout);
29
+ _expectResponseCode (200 , response);
30
+ // Use the compute function to run parseSchedules in a separate isolate.
31
+ return compute (_parseSchedules, response.body);
32
+ } on TimeoutException catch (te, stacktrace) {
33
+ return Future .error (te, stacktrace);
34
+ }
30
35
}
31
36
32
37
Future <Schedule > getSchedule (String id) async {
33
38
final uri = Uri .http (apiUrl, '$scheduleEndpoint /$id ' );
34
- final response = await httpClient.get (uri);
39
+ final response = await httpClient.get (uri). timeout (timeout) ;
35
40
_expectResponseCode (200 , response);
36
41
return deserialize <Schedule >(jsonDecode (response.body));
37
42
}
@@ -40,14 +45,14 @@ Future<Schedule> putSchedule(Schedule schedule, String id) async {
40
45
final uri = Uri .http (apiUrl, '$scheduleEndpoint /$id ' );
41
46
final response = await httpClient.put (uri,
42
47
headers: applicationJsonHeader,
43
- body: jsonEncode (serialize <Schedule >(schedule)));
48
+ body: jsonEncode (serialize <Schedule >(schedule))). timeout (timeout) ;
44
49
_expectResponseCode (200 , response);
45
50
return deserialize <Schedule >(jsonDecode (response.body));
46
51
}
47
52
48
53
Future <Schedule > deleteSchedule (Schedule schedule, String id) async {
49
54
final uri = Uri .http (apiUrl, '$scheduleEndpoint /$id ' );
50
- final response = await httpClient.delete (uri);
55
+ final response = await httpClient.delete (uri). timeout (timeout) ;
51
56
_expectResponseCode (200 , response);
52
57
return deserialize <Schedule >(jsonDecode (response.body));
53
58
}
0 commit comments