Giter Site home page Giter Site logo

Asynchronous sleeping about geoip HOT 3 CLOSED

kuno avatar kuno commented on August 15, 2024
Asynchronous sleeping

from geoip.

Comments (3)

kuno avatar kuno commented on August 15, 2024

"This callback will be ran inside a thread managed by libeio. The first step is to extract the baton structure, so we have access to our context. Next we sleep for the value of baton->sleep_for, which is safe to do, because we are in a thread, and not blocking all Javascript execution in the main thread. Then we do the work of incrementing the count, which if this wasn't just a simple example you would want to wrap in a Lock/Mutex."

https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/

from geoip.

jbt avatar jbt commented on August 15, 2024

In that example, the sleep was used just to demonstrate that the execution is non-blocking. It seems to have no use in this module. It's delaying the callback execution for no reason (as far as I can see). If I'm running this module in a situation where I need to look up thousands of IP records every second, I can't have it waiting for a whole second before executing the callback every time.

from geoip.

kuno avatar kuno commented on August 15, 2024

let me make it clear.
The is my first c++ addon for nodejs. So I just followed that tutorial during the whole process of build this package.
Honestly, the async(non-blocking) methods are just for demonstration and very rare situations at this point of time.
Because the databases are cached in the memory in most cases, the concept of non-blocking dose not apply to these cases.
So you should always use synchronous methods (e.g city.lookupSync ), at least in the normal cases.
If this make your confused, this is my fault,I am apologize for that.

--kuno

from geoip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.