File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,8 @@ func (i *Internal) CancelableCtx() context.Context {
171
171
}
172
172
173
173
// New creates new instances of Task.
174
- func New (fn func (t * Internal )) * Task {
174
+ // Accepts `func()` or `func(t *Internal)`
175
+ func New (fn interface {}) * Task {
175
176
// Spin up some channels
176
177
done := make (chan struct {}, 1 )
177
178
stopper := make (chan struct {}, 1 )
@@ -203,12 +204,17 @@ func New(fn func(t *Internal)) *Task {
203
204
})
204
205
205
206
// Execute the task
206
- fn (& Internal {
207
- Resolver : tiResolver ,
208
- Rejector : tiRejector ,
209
- Stopper : t .Stopper ,
210
- done : & done ,
211
- })
207
+ switch v := fn .(type ) {
208
+ case func ():
209
+ v ()
210
+ case func (t * Internal ):
211
+ v (& Internal {
212
+ Resolver : tiResolver ,
213
+ Rejector : tiRejector ,
214
+ Stopper : t .Stopper ,
215
+ done : & done ,
216
+ })
217
+ }
212
218
213
219
// Read the result in a non blocking manner. Keep in mind not every task
214
220
// will actually resolve or reject anything, the simple fact that it is
You can’t perform that action at this time.
0 commit comments