Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow return result and error instead of throw error #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

itswisdomagain
Copy link

Different calls may produce different errors that may need to be handled differently. Users can set a flag to disable throwing exceptions on error.

Examples

var deferReturnError = sync.defer(true);
sync.fiber(function() {
    var fnCallResult = sync.await(asyncFunction(deferReturnError));
    var err = fnCallResult.error; var result = fnCallResult.result;
}
synchronizedFn = sync(asyncFunction);
sync.fiber(function() {
    var fnCallResult = synchronizedFn(arg1, arg2, sync.returnErrorValue);
    var err = fnCallResult.error; var result = fnCallResult.result;
}

Or ES6 style

var deferReturnError = sync.defer(true);
sync.fiber(function() {
    const { error, result } = sync.await(asyncFunction(deferReturnError));
}
synchronizedFn = sync(asyncFunction);
sync.fiber(function() {
    const { error, result }  = synchronizedFn(arg1, arg2, sync.returnErrorValue);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant