event-driven

Non-blocking (async) DNS resolving in Java

穿精又带淫゛_ 提交于 2019-12-31 17:49:30
问题 Is there a clean way to resolve a DNS query (get IP by hostname) in Java asynchronously, in non-blocking way (i.e. state machine, not 1 query = 1 thread - I'd like to run tens of thousands queries simultaneously, but not run tens of thousands of threads)? What I've found so far: Standard InetAddress.getByName() implementation is blocking and looks like standard Java libraries lack any non-blocking implementations. Resolving DNS in bulk question discusses similar problem, but the only solution

Microservice data replication patterns

﹥>﹥吖頭↗ 提交于 2019-12-21 17:53:20
问题 In a microservice architecture, we usually have two ways to communicate 2 microservices. Let’s say service A needs to get information from service B. The first option is an remote call, usually synchronous over HTTPS, so service A query an API hosted by service B. The second option is adopting an event-driven architecture, where the state of service B can be published and consumed by service A in asynchronous way. Using this model, the service A can update its own database with the

Python - How can I make this code asynchronous?

这一生的挚爱 提交于 2019-12-21 04:08:16
问题 Here's some code that illustrates my problem: def blocking1(): while True: yield 'first blocking function example' def blocking2(): while True: yield 'second blocking function example' for i in blocking1(): print 'this will be shown' for i in blocking2(): print 'this will not be shown' I have two functions which contain while True loops. These will yield data which I will then log somewhere (most likely, to an sqlite database). I've been playing around with threading and have gotten it

why Redis is single threaded(event driven)

空扰寡人 提交于 2019-12-21 03:01:20
问题 I am trying to understanding basics of Redis. One that that keep coming everywhere is, Redis is single threaded that makes things atomic.But I am unable to imagine how this is working internally.I have below doubt. Don't we design a server Single thread if it is IO bound application(like Node.js),where thread got free for another request after initiating IO operation and return data to client once IO operation is finished(providing concurrency). But in case of redis all data are available in

What's the correct way to implement the equivalent of multiple mutable (statically allocated, statically dispatched, etc.) callbacks in Rust?

穿精又带淫゛_ 提交于 2019-12-17 21:15:14
问题 I have the following example code, which is the standard basis of event-driven APIs in other programming languages, but in Rust the borrow checker blocks it with "cannot borrow p1 as mutable more than once at a time": struct Pen { color_cmyk: u32, ink: usize, } impl Pen { pub fn new() -> Pen { Pen { color_cmyk: 0x80800000, ink: 20000, } } pub fn write(&mut self, text: &str) -> bool { if self.ink < text.len() { return false; } self.ink -= text.len(); true } } fn main() { println!("Hello, world

Dealing with exceptions in an event driven world

大兔子大兔子 提交于 2019-12-14 03:59:58
问题 I'm trying to understand how exceptions are handled in an event driven world using micro-services (using apache kafka). For example, if you take the following order scenario whereby the following actions need to happen before the order can be completed. 1) Authorise the payment with the payment service provider 2) Reserve the item from stock 3.1) Capture the payment with the payment service provider 3.2) Order the item 4) Send a email notification accepting the order with a receipt At any

Contentious paralleled work between two collections of objects

大憨熊 提交于 2019-12-13 02:46:05
问题 I am trying to simulate work between two collections asynchronously and in parallel, I have a ConcurrentQueue of customers and a collection of workers. I need the workers to take a Customer from the queue perform work on the customer and once done take another customer right away. I decided I'd use an event-based paradigm where the collection of workers would perform an action on a customer; who holds an event handler that fires off when the customer is done; which would hopefully fire off

In Scala, how would I combine event driven programming with a functional approach?

旧城冷巷雨未停 提交于 2019-12-12 07:09:47
问题 To clarify what I mean by event driven I'm referring to a situation where I have def onTrade(...) Which is called every time a particular stock trades. Suppose I want to track the daily highest trade price. To me the obvious solution is: var dailyHigh = 0 def onTrade(...) { if (price > dailyHigh) dailyHigh = price } Is there a way to achieve this functionality using val instead of var? Assume also that I may want to add dailyLow, volumeHigh, volumeLow etc in the future. 回答1: Not much of a

Designing a simple event-driven GUI

谁说胖子不能爱 提交于 2019-12-12 03:39:43
问题 I am creating a simple event-driven GUI for a video game I am making with LibGDX. It only needs to support buttons (rectangular) with a single act() function called when they are clicked. I would appreciate some advice on structuring because the solution I've thought of so far seems to be far from ideal. My current implementation involves all buttons extending a Button class. Each button has a Rectangle with its bounds and an abstract act() method. Each game screen (e.g. main menu, character

Rails: How to have no response until an event triggers

十年热恋 提交于 2019-12-12 01:48:09
问题 I don't know if Rails has a way to do as following: Receive a request Put the request into the monitor list until an event triggers Finish the request but does not return any response to the client (no HTTP response), the trigger will do the response later after processing. I found some info about delayed_job, but it returns the response immediately and puts the job to the background which does not seem to be event-driven. Anyone can help? Andy. 回答1: I think you are talking about callbacks.