FastArduino  v1.9 alpha
C++ library to build fast but small Arduino/AVR projects
future.cpp
1 // Copyright 2016-2022 Jean-Francois Poilpret
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "future.h"
16 
17 namespace future
18 {
20  // Add utility ostream manipulator for FutureStatus
21  static const flash::FlashStorage* convert(future::FutureStatus s)
22  {
23  switch (s)
24  {
26  return F("NOT_READY");
27 
29  return F("READY");
30 
32  return F("ERROR");
33 
35  return F("INVALID");
36  }
37  }
38 
40  {
41  return out << convert(s);
42  }
44 }
Output stream wrapper to provide formatted output API, a la C++.
Definition: streams.h:61
#define F(ptr)
Force string constant to be stored as flash storage.
Definition: flash.h:118
Utility API to handle the concept of futures.
Contains the API around Future implementation.
Definition: future.cpp:18
FutureStatus
Status of a Future.
Definition: future.h:320
@ READY
The status of a Future once its output value has been fully set by a provider.
@ NOT_READY
The status of a Future immediately after it has been constructed.
@ ERROR
The status of a Future once a value provider has reported an error to it.
@ INVALID
The status of a Future that has been moved, if it was NOT_READY before moving.