1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SRC_ASYNC_WRAP_H_
23 #define SRC_ASYNC_WRAP_H_
25 #include "base-object.h"
31 class AsyncWrap : public BaseObject {
38 inline AsyncWrap(Environment* env, v8::Handle<v8::Object> object);
42 template <typename Type>
43 static inline void AddMethods(v8::Handle<v8::FunctionTemplate> t);
45 inline uint32_t async_flags() const;
47 inline void set_flag(unsigned int flag);
49 inline void remove_flag(unsigned int flag);
51 inline bool has_async_queue();
53 // Only call these within a valid HandleScope.
54 inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
56 v8::Handle<v8::Value>* argv);
57 inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol,
59 v8::Handle<v8::Value>* argv);
60 inline v8::Handle<v8::Value> MakeCallback(uint32_t index,
62 v8::Handle<v8::Value>* argv);
65 // Add an async listener to an existing handle.
66 template <typename Type>
67 static inline void AddAsyncListener(
68 const v8::FunctionCallbackInfo<v8::Value>& args);
70 // Remove an async listener to an existing handle.
71 template <typename Type>
72 static inline void RemoveAsyncListener(
73 const v8::FunctionCallbackInfo<v8::Value>& args);
75 uint32_t async_flags_;
81 #endif // SRC_ASYNC_WRAP_H_