简体   繁体   中英

this.unblock in a method if the method is non-blocking

I would like to know if I need to use this.unblock() inside a Meteor method if the method is already non-blocking.

Here is a contrived example:

Meteor.methods({
  myMethod() {
    this.unblock();

    someAPIWrapper(params, function (err, res) {
      // do something with res asynchronously
    });
  }
});

myMethod makes an HTTP call using some node.js wrapper for a third party API. It is asynchronous.

In this case, is there a performance gain by using this.unblock() ?

Basically no.

this.unblock() allows the execution of ordered method calls from a single client to continue within a new fiber because the current one is blocked by a synchronous operation.

So as long as your method body does not do any work that blocks the current fiber, you don't need to unblock it explicitly. In fact, it may even cause its own overhead due to creation of new unnecessary fibers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM