Skip to content

Fluent interface to catch exceptions - #47

Closed
thekid wants to merge 3 commits into
masterfrom
feature/catch
Closed

Fluent interface to catch exceptions#47
thekid wants to merge 3 commits into
masterfrom
feature/catch

Conversation

@thekid

@thekidthekid commented Oct 31, 2017

Copy link
Copy Markdown
Member

Example

Sequence::of($import)
->peek(function($record) { Console::write($record['name']); })
->map(function($record) {
$existing= $this->database->lookup($record['name']);
return$this->database->replace($existing, $record);
})
->catch(function($e) { $e->printStackTrace(); })
->peek(function($id) { Console::writeLine(' -> #', $id); )
->each()
;

BC break

⚠️Sequence::$EMPTY needs to b rewritten as Sequence::empty().

Performance

This pull request introduces wide-ranging implementation changes, which also have a slight performance hit:

# [feature/catch]
$ xp -m ../measure/ measure -n 1000 Operations
counting: 1000 iteration(s), 1.159 seconds, result= 10000
collecting: 1000 iteration(s), 2.067 seconds, result= 10000
# [master]
$ xp -m ../measure/ measure -n 1000 Operations
counting: 1000 iteration(s), 1.013 seconds, result= 10000
collecting: 1000 iteration(s), 1.857 seconds, result= 10000

See also http://reactivex.io/documentation/operators/catch.html and #30

} catch (\Throwable $t) {
$this->error= $t;
} catch (\Exception $e) {
$this->error= $e;

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about wrapping this in a lang.Throwabe.

@thekid

Copy link
Copy Markdown
MemberAuthor

#30 seems to cover more usecases

@thekidthekid closed this Sep 30, 2019
@thekid
thekid deleted the feature/catch branch September 30, 2019 10:47
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@thekid