From 7da970886a08f093966f9ecd457dbc91045411ca Mon Sep 17 00:00:00 2001 From: Nuruddin Ashr Date: Sat, 6 Apr 2024 00:20:18 +0700 Subject: [PATCH] Utilize defer --- future.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/future.go b/future.go index bbf698b..7cb0647 100644 --- a/future.go +++ b/future.go @@ -63,17 +63,17 @@ func (f *Future[T]) Listen(callback SetResultFunc[T]) { callback(f.val, f.err) default: f.mu.Lock() + defer f.mu.Unlock() f.callbacks = append(f.callbacks, callback) - f.mu.Unlock() } } func (f *Future[T]) notifyCallbacks() { f.mu.Lock() + defer f.mu.Unlock() for _, callback := range f.callbacks { callback(f.val, f.err) } - f.mu.Unlock() } // Call will converts the sync function call as async call.