doComplete executes the completion callback function, double-checking when setting the processing result and callback function to prevent the possibility of not calling the callback function (执行完成回调,在设置处理结果和回调函数的时候双重检查,杜绝未调用回调函数的可能性)
()
| 64 | // doComplete executes the completion callback function, double-checking when setting the processing result and callback function to prevent the possibility of not calling the callback function |
| 65 | // (执行完成回调,在设置处理结果和回调函数的时候双重检查,杜绝未调用回调函数的可能性) |
| 66 | func (aor *AsyncOpResult) doComplete() { |
| 67 | v := aor.completeFunc.Load() |
| 68 | if v == nil { |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | cf := v.(func()) |
| 73 | |
| 74 | // Prevent re-entry problems (防止可重入问题) |
| 75 | if atomic.CompareAndSwapInt32(&aor.completeFuncHasAlreadyBeenCalled, 0, 1) { |
| 76 | // Prevent cross-thread calling problems, |
| 77 | // throw it to the corresponding business thread to execute |
| 78 | // (防止跨线程调用问题,扔到所属业务线程里去执行) |
| 79 | request := znet.NewFuncRequest(aor.conn, cf) |
| 80 | aor.conn.GetMsgHandler().SendMsgToTaskQueue(request) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // NewAsyncOpResult creates a new asynchronous result(新建异步结果) |
| 85 | func NewAsyncOpResult(conn ziface.IConnection) *AsyncOpResult { |
no test coverage detected