3

Say I have multiple hooks defined for the same remote method on the same remote model:

MyModel.afterRemote('create', function (context, instance, next) {
    // Do A
})

MyModel.afterRemote('create', function (context, instance, next) {
    // Do B
})

MyModel.afterRemote('create', function (context, instance, next) {
    // Do C
})

Will loopback execute these sequentially in order of definition, e.g. will A finish before B and so forth?

csvan
  • 8,782
  • 12
  • 48
  • 91
  • I'm pretty sure that is the case. The hooks simply add "middleware" to the request handling, and each middleware would need to wait until `next()` is called in the previous one. Have you tried this? Did it not work that way? – Jordan Kasper Feb 01 '16 at 16:07
  • @jakerella That is true only in case that there are no asynchronous operations inside callback functions "Do A", "Do B" and "Do C". If you have any asynchronous operation before next() then there is no guarantee that operations inside callbacks will be finished in any particular order. – A.Z. Feb 03 '16 at 13:07
  • @A.Z. your observation is correct, but my question implies that `next()` is the last call made in any of the hooks (e.g. inside a callback if there are async ops, etc). – csvan Feb 03 '16 at 16:31
  • @csvan This is something I'm looking for an answer on right now. Any further info? – sidewaiise Aug 16 '17 at 02:04

0 Answers0