locked
Strange issue when I try to compositon multiple async function using PPL.

    Question

  • Hi, I met a strange issue when I try to chain several async function using PPL, here are the samples I used to simplify the calling sequence for BitmapDecoder,

    In general, these code works.

    But after I insert a line to keep some setting, I got the compile error?

    Does anybody know what happened?

    Thank you~~

    Eric

     

    IAsyncOperation<int>^ ImageReader::initialize(String^ url, IRandomAccessStream^ stream)
    {
        auto op = create_async([=] () -> task<int>  {

            auto decoder = BitmapDecoder::CreateAsync(stream);
            task<BitmapDecoder^> getDecoderTask(decoder);
            return getDecoderTask.then([=](BitmapDecoder^ decoder) {
                unsigned int width = decoder->OrientedPixelWidth;   ================> this line causes compile error.
                return decoder->GetPixelDataAsync();
            }).then([=] (PixelDataProvider^ pixProvider) -> int {
                return 1;
            });

        });

        return op;
    }

    Tuesday, December 6, 2011 2:55 AM

Answers

  •  Peng,
    You're missing a return value declaration on your lambda. The compiler can deduce the return value if you just have a single statement in your lambda that is a return statement, but the moment you add more lines in there, it needs you to declare the return type. Try this:
     
    IAsyncOperation<int>^ ImageReader::initialize(String^ url, IRandomAccessStream^ stream)
    {
          auto op = create_async([=] () -> task<int> {
    
              auto decoder = BitmapDecoder::CreateAsync(stream);
             task<BitmapDecoder^> getDecoderTask(decoder);
             return getDecoderTask.then([=](BitmapDecoder^ decoder) -> IAsyncOperation<PixelDataProvider^>^ {
                 unsigned int width = decoder->OrientedPixelWidth; 
                  return decoder->GetPixelDataAsync();
             }).then([=] (PixelDataProvider^ pixProvider) -> int {
                  return 1;
              });
        });
    
          return op;
    }
    
    • Marked as answer by Peng Huan Hung Thursday, December 15, 2011 6:58 AM
    Tuesday, December 13, 2011 8:46 PM

All replies

  • Hi Eric,

     

    Could you share the compiler error you received?

     

    Thanks,

    -David

    Tuesday, December 13, 2011 3:52 AM
    Moderator
  •  Peng,
    You're missing a return value declaration on your lambda. The compiler can deduce the return value if you just have a single statement in your lambda that is a return statement, but the moment you add more lines in there, it needs you to declare the return type. Try this:
     
    IAsyncOperation<int>^ ImageReader::initialize(String^ url, IRandomAccessStream^ stream)
    {
          auto op = create_async([=] () -> task<int> {
    
              auto decoder = BitmapDecoder::CreateAsync(stream);
             task<BitmapDecoder^> getDecoderTask(decoder);
             return getDecoderTask.then([=](BitmapDecoder^ decoder) -> IAsyncOperation<PixelDataProvider^>^ {
                 unsigned int width = decoder->OrientedPixelWidth; 
                  return decoder->GetPixelDataAsync();
             }).then([=] (PixelDataProvider^ pixProvider) -> int {
                  return 1;
              });
        });
    
          return op;
    }
    
    • Marked as answer by Peng Huan Hung Thursday, December 15, 2011 6:58 AM
    Tuesday, December 13, 2011 8:46 PM
  • Thanks, it works~

     

    Eric

    Thursday, December 15, 2011 7:01 AM