-
Notifications
You must be signed in to change notification settings - Fork 331
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
support for async callback #81
Comments
You'll need to wrap your async callback as Bacon EventStream and then you can use flatMap to achieve this. FlatMap maps an event to a EventStream and merges the created streams to result stream. $(".ss").asEventStream("click").flatMap(function(e) {
return Bacon.later(1000, 5000);
}); There isn't a direct method to wrap callbacks, but if you're dealing with AJAX, stream.flatMap(function(e) {
var bus = new Bacon.Bus()
setTimeout(function() {
bus.push(5000);
bus.end()
},1000);
return bus;
}); |
@lautis thanks! Nice solution. An even simpler solution to this particular problem would be
The flatMap solution is more flexible though. (Have a look at the implementation to Would it make sense to include an easy callback wrapper API? If it existed, how would you like your client code to look like? |
In fact, there is
Looks clumsy, of course, compared to the specific solution using |
Oh, cool. That's what I imagined the API for fromCallback to be. It's handy if you need to wrap a third party library to a Bacon stream (e.g. Zepto.js AJAX, which doesn't use promises). |
thanks it really work like i want |
Hi,
there is a callback for async callback in map and other functions?
for example
function log should write 5000
The text was updated successfully, but these errors were encountered: