mirror of
https://github.com/Naios/continuable.git
synced 2026-02-07 02:09:46 +08:00
mockups of new methods
This commit is contained in:
parent
e002775e92
commit
aff69c5aa4
@ -202,15 +202,28 @@ namespace detail
|
|||||||
}, std::move(*this));
|
}, std::move(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Placeholder
|
||||||
// TODO Accept only correct callbacks
|
|
||||||
template<typename... _CTy>
|
template<typename... _CTy>
|
||||||
Continuable<Callback<_ATy...>> all(_CTy&&...)
|
_ContinuableImpl& all(_CTy&&...)
|
||||||
{
|
{
|
||||||
// TODO Transmute the returned callback here.
|
return *this;
|
||||||
return Continuable<Callback<_ATy...>>(std::move(*this));
|
}
|
||||||
|
|
||||||
|
/// Placeholder
|
||||||
|
template<typename... _CTy>
|
||||||
|
_ContinuableImpl& some(size_t const count, _CTy&&...)
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placeholder
|
||||||
|
template<typename... _CTy>
|
||||||
|
auto any(_CTy&&... functionals)
|
||||||
|
-> decltype(some(1, std::declval<_CTy>()...))
|
||||||
|
{
|
||||||
|
// Equivalent to invoke `some` with count 1.
|
||||||
|
return some(1, std::forward<_CTy>(functionals)...);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// Validates the Continuable
|
/// Validates the Continuable
|
||||||
@ -307,4 +320,19 @@ inline auto make_continuable(_FTy&& functional)
|
|||||||
return detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional));
|
return detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates an empty continuable.
|
||||||
|
/// Can be used to start a chain with aggregate methods.
|
||||||
|
/// empty_continuable()
|
||||||
|
/// .all(...)
|
||||||
|
/// .some(...)
|
||||||
|
/// .any(...)
|
||||||
|
inline auto empty_continuable()
|
||||||
|
-> Continuable<>
|
||||||
|
{
|
||||||
|
return make_continuable([](Callback<>&& callback)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _CONTINUABLE_H_
|
#endif // _CONTINUABLE_H_
|
||||||
|
|||||||
32
test.cpp
32
test.cpp
@ -44,6 +44,18 @@ Continuable<SpellCastResult> CastSpellPromise(int id)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Void instant returning continuable promise for testing purposes
|
||||||
|
Continuable<> TrivialPromise(std::string const& msg = "")
|
||||||
|
{
|
||||||
|
return make_continuable([=](Callback<>&& callback)
|
||||||
|
{
|
||||||
|
if (!msg.empty())
|
||||||
|
std::cout << msg << std::endl;
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Continuable<bool> Validate()
|
Continuable<bool> Validate()
|
||||||
{
|
{
|
||||||
return make_continuable([=](Callback<bool>&& callback)
|
return make_continuable([=](Callback<bool>&& callback)
|
||||||
@ -84,6 +96,26 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
return Validate();
|
return Validate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Mockup of aggregate methods
|
||||||
|
empty_continuable()
|
||||||
|
.all(
|
||||||
|
[] { return TrivialPromise(); },
|
||||||
|
[] { return TrivialPromise(); },
|
||||||
|
[] { return TrivialPromise(); }
|
||||||
|
)
|
||||||
|
.some(2, // Only 2 of 3 must complete
|
||||||
|
[] { return TrivialPromise(); },
|
||||||
|
[] { return TrivialPromise(); },
|
||||||
|
[] { return TrivialPromise(); }
|
||||||
|
)
|
||||||
|
.any( // Any of 2.
|
||||||
|
[] { return TrivialPromise(); },
|
||||||
|
[] { return TrivialPromise(); }
|
||||||
|
)
|
||||||
|
.then([]
|
||||||
|
{
|
||||||
|
});
|
||||||
|
|
||||||
//Continuable<bool> cb = make_continuable([](Callback<bool>&& callback)
|
//Continuable<bool> cb = make_continuable([](Callback<bool>&& callback)
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user