CAF icon indicating copy to clipboard operation
CAF copied to clipboard

Improve error when `signal` isn't passed down correctly to a sub-CAF

Open aguynamedben opened this issue 3 years ago • 1 comments

Thank you (again!) for this great project. It's a lifesaver if you need to timeout Promise-based code. 🙏

I just wanted to document a potential improvement. We have code that uses CAF to add timeouts around async code. Within one CAF function we pass signal down to sub-CAF functions. This lets us separate async logic but still have it elegantly timeout.

But! If you forget to pass signal down to a sub-CAF function that expects it, a fairly unhelpful error is show: image

Code example

// within a CAF function, call a sub-CAF function, but we forgot to pass `signal`
yield this.getAndSyncUsers(syncRequest, conversationMembers.members, seenUsers);

// signature for the sub-CAF function, but we forgot to accept `signal`
static getAndSyncUsers = CAF(function *getAndSyncUsers(
  syncRequest: SyncRequest,
  users: Array,
  seenUsers: Object,
) {
  // ...implementation...
});

aguynamedben avatar Mar 29 '22 22:03 aguynamedben

Thanks for the helpful suggestion. Will keep this in mind for the next update. :)

getify avatar Mar 29 '22 23:03 getify