mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-05 03:03:34 +00:00
1. Updated 'addMethod' on emitter, to return this, so you can chain multiple together
2. Updated wget return value to expose an 'abort' event
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -752,7 +752,9 @@ duk_ret_t ILibDuktape_EventEmitter_Inherits_addMethod(duk_context *ctx)
|
||||
|
||||
duk_push_heapptr(ctx, emitter->object); // [emitterUtils][ptr][target]
|
||||
ILibDuktape_CreateProperty_InstanceMethodEx(ctx, (char*)duk_require_string(ctx, 0), duk_require_heapptr(ctx, 1));
|
||||
return(0);
|
||||
|
||||
duk_push_this(ctx);
|
||||
return(1);
|
||||
}
|
||||
duk_ret_t ILibDuktape_EventEmitter_EmitterUtils_Finalizer(duk_context *ctx)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,10 @@ function wget(remoteUri, localFilePath)
|
||||
{
|
||||
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
var agentConnected = false;
|
||||
require('events').EventEmitter.call(ret, true).createEvent('bytes');
|
||||
require('events').EventEmitter.call(ret, true)
|
||||
.createEvent('bytes')
|
||||
.createEvent('abort')
|
||||
.addMethod('abort', function () { this._request.abort(); });
|
||||
|
||||
try
|
||||
{
|
||||
@@ -53,14 +56,11 @@ function wget(remoteUri, localFilePath)
|
||||
}
|
||||
|
||||
ret._totalBytes = 0;
|
||||
ret.abort = function()
|
||||
{
|
||||
this._request.abort();
|
||||
}
|
||||
ret._request = http.get(remoteUri);
|
||||
ret._localFilePath = localFilePath;
|
||||
ret._request.promise = ret;
|
||||
ret._request.on('error', function (e) { this.promise._rej(e); });
|
||||
ret._request.on('abort', function () { this.promise.emit('abort'); });
|
||||
ret._request.on('response', function (imsg)
|
||||
{
|
||||
if(imsg.statusCode != 200)
|
||||
|
||||
Reference in New Issue
Block a user