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

Add Promise#spawn. #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/flog.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
threshold: 15.8
threshold: 15.6
16 changes: 15 additions & 1 deletion lib/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def rejected?

def then(on_fulfill = nil, on_reject = nil, &block)
on_fulfill ||= block
next_promise = self.class.new
next_promise = spawn

case state
when :fulfilled
Expand Down Expand Up @@ -156,6 +156,20 @@ def subscribe(observer, on_fulfill_arg, on_reject_arg)

protected

# Spawn a new Promise.
#
# This method is called by `#then` to create a new Promise.
#
# The default implementation returns a new instance of the same
# class as the promise on which `#then` was called. This can be overridden
# by subclasses to return promise instances of a different class to be used
# for chaining.
#
# @return [Promise]
def spawn
self.class.new
end

# Override to defer calling the callback for Promises/A+ spec compliance
def defer
yield
Expand Down