Skip to content

Commit

Permalink
this commit marks the release point of version 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Dec 26, 2015
1 parent 1409658 commit 749da27
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions task.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace Task

T q ;

m_function = [ & ]( T r ){ q = std::move( r ) ; p.exit() ; } ;
m_function = [ & ]( T&& r ){ q = std::move( r ) ; p.exit() ; } ;

this->start() ;

Expand All @@ -146,7 +146,7 @@ namespace Task
{
m_cancel() ;
}
void run( T r )
void run( T&& r )
{
m_function( std::move( r ) ) ;
}
Expand Down Expand Up @@ -310,12 +310,6 @@ namespace Task
{
return Task::await<T>( std::bind( std::move( function ),std::move( args ) ... ) ) ;
}

template< typename ... Args >
void await( std::function< void( Args ... ) > function,Args ... args )
{
Task::await< void >( std::bind( std::move( function ),std::move( args ) ... ) ) ;
}

static inline void await( std::function< void() > function )
{
Expand Down Expand Up @@ -430,6 +424,36 @@ alternatively,

int r = Task::run<int>( _a ).await() ;

*******************************************************************
* Example use cases on how to use lambda that requires an argument
*******************************************************************

/*
* declaring "meaw" with an auto keyword will not be sufficient here
* and the full std::function<blablabla> is required.
*
* For the same reason,just plugging in a lambda that requires arguments
* into Task::run() will not be sufficent and the plugged in lambda must
* be casted to std::function<blablabla> for it to compile.
*
* Why the above restriction? No idea but i suspect it has to do with
* variadic template type deduction failing to see something.
*/

std::function< int( int ) > meaw = []( int x ){

return x + 1 ;
} ;

Task::run( meaw,6 ).then( []( int r ){

qDebug() << r ;
} ) ;

alternatively,

r = Task::await( meaw,6 ) ;

#endif //end example block

#endif //__TASK_H_INCLUDED__

0 comments on commit 749da27

Please sign in to comment.