Tuesday, 14 March 2017

node-celery asychronise, await client.call() finish it's inner function

I am using node-celery 0.2.8 in my node.js server,and I create, use await on client.on(), hoping the code will console log result first, then log 'finally'. But the code console log 'finally' first, then after go through all the code, console log result. Could anyone help me to let the await work on client.on()? I just hope the code can execute in order, and wait at the asychronise request.

async(ctx) => {
  const client = celery.createClient({
    CELERY_BROKER_URL: 'amqp://guest:guest@172.**.2.**:5672//',
    CELERY_RESULT_BACKEND: 'redis://172.**.2.**:6379/2',
    CELERY_ROUTES: {
      'street.add_account_multi': {'queue': 'street_default'},
    }
  });

  await client.on('connect', () => {

    client.call('street.add_account_multi', [crawlers], function (result) {
      console.log(result);
    });

  });

  console.log('finally');
}



via JACK

No comments:

Post a Comment