promise.qbk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. [/
  2. Copyright Oliver Kowalke 2013.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt
  6. ]
  7. [#class_promise]
  8. [section:promise Template `promise<>`]
  9. A __promise__ provides a mechanism to store a value (or exception) that can
  10. later be retrieved from the corresponding __future__ object. `promise<>` and
  11. `future<>` communicate via their underlying [link shared_state shared state].
  12. #include <boost/fiber/future/promise.hpp>
  13. namespace boost {
  14. namespace fibers {
  15. template< typename R >
  16. class promise {
  17. public:
  18. promise();
  19. template< typename __Allocator__ >
  20. promise( __allocator_arg_t__, Allocator);
  21. promise( promise &&) noexcept;
  22. promise & operator=( promise &&) noexcept;
  23. promise( promise const&) = delete;
  24. promise & operator=( promise const&) = delete;
  25. ~promise();
  26. void swap( promise &) noexcept;
  27. future< R > get_future();
  28. void set_value( R const&); // member only of generic promise template
  29. void set_value( R &&); // member only of generic promise template
  30. void set_value( R &); // member only of promise< R & > template
  31. void set_value(); // member only of promise< void > template
  32. void set_exception( std::exception_ptr p);
  33. };
  34. template< typename R >
  35. void swap( promise< R > &, promise< R > &) noexcept;
  36. }
  37. [heading Default constructor]
  38. promise();
  39. [variablelist
  40. [[Effects:] [Creates a promise with an empty [link shared_state shared state].]]
  41. [[Throws:] [Exceptions caused by memory allocation.]]
  42. ]
  43. [heading Constructor]
  44. template< typename __Allocator__ >
  45. promise( __allocator_arg_t__, Allocator alloc);
  46. [variablelist
  47. [[Effects:] [Creates a promise with an empty [link shared_state shared state] by using `alloc`.]]
  48. [[Throws:] [Exceptions caused by memory allocation.]]
  49. [[See also:] [__allocator_arg_t__]]
  50. ]
  51. [heading Move constructor]
  52. promise( promise && other) noexcept;
  53. [variablelist
  54. [[Effects:] [Creates a promise by moving the [link shared_state shared state] from `other`.]]
  55. [[Postcondition:] [`other` contains no valid shared state.]]
  56. [[Throws:] [Nothing.]]
  57. ]
  58. [heading Destructor]
  59. ~promise();
  60. [variablelist
  61. [[Effects:] [Destroys `*this` and abandons the [link shared_state shared
  62. state] if shared state is ready; otherwise stores __future_error__ with error
  63. condition __broken_promise__ as if by [member_link promise..set_exception]:
  64. the shared state is set ready.]]
  65. ]
  66. [operator_heading promise..operator_assign..operator=]
  67. promise & operator=( promise && other) noexcept;
  68. [variablelist
  69. [[Effects:] [Transfers the ownership of [link shared_state shared state] to `*this`.]]
  70. [[Postcondition:] [`other` contains no valid shared state.]]
  71. [[Throws:] [Nothing.]]
  72. ]
  73. [member_heading promise..swap]
  74. void swap( promise & other) noexcept;
  75. [variablelist
  76. [[Effects:] [Swaps the [link shared_state shared state] between other and `*this`.]]
  77. [[Throws:] [Nothing.]]
  78. ]
  79. [member_heading promise..get_future]
  80. future< R > get_future();
  81. [variablelist
  82. [[Returns:] [A __future__ with the same [link shared_state shared state].]]
  83. [[Throws:] [__future_error__ with __already_retrieved__ or __no_state__.]]
  84. ]
  85. [member_heading promise..set_value]
  86. void set_value( R const& value); // member only of generic promise template
  87. void set_value( R && value); // member only of generic promise template
  88. void set_value( R & value); // member only of promise< R & > template
  89. void set_value(); // member only of promise< void > template
  90. [variablelist
  91. [[Effects:] [Store the result in the [link shared_state shared state] and marks the state as ready.]]
  92. [[Throws:] [__future_error__ with __already_satisfied__ or __no_state__.]]
  93. ]
  94. [member_heading promise..set_exception]
  95. void set_exception( std::exception_ptr);
  96. [variablelist
  97. [[Effects:] [Store an exception pointer in the [link shared_state shared state] and marks the state as ready.]]
  98. [[Throws:] [__future_error__ with __already_satisfied__ or __no_state__.]]
  99. ]
  100. [function_heading_for swap..promise]
  101. template< typename R >
  102. void swap( promise< R > & l, promise< R > & r) noexcept;
  103. [variablelist
  104. [[Effects:] [Same as `l.swap( r)`.]]
  105. ]
  106. [endsect]