forked from microsoft/Chakra-Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Promise handling and a really basic event loop
- Loading branch information
Showing
9 changed files
with
312 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ChakraCore Samples/JSRT Hosting Samples/C#/ChakraCoreHost/Tasks/ActionTaskItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChakraCoreHost.Tasks | ||
{ | ||
public class ActionTaskItem : TaskItem | ||
{ | ||
private Action action; | ||
|
||
public ActionTaskItem(Action action) | ||
{ | ||
this.action = action; | ||
} | ||
|
||
public override void Run() | ||
{ | ||
this.action.Invoke(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
ChakraCore Samples/JSRT Hosting Samples/C#/ChakraCoreHost/Tasks/JsTaskItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using ChakraHost.Hosting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChakraCoreHost.Tasks | ||
{ | ||
public class JsTaskItem : TaskItem | ||
{ | ||
private JavaScriptValue taskFunc; | ||
|
||
public JsTaskItem(JavaScriptValue taskFunc) | ||
{ | ||
this.taskFunc = taskFunc; | ||
|
||
// We need to keep the object alive in the Chakra GC. | ||
this.taskFunc.AddRef(); | ||
} | ||
|
||
~JsTaskItem() | ||
{ | ||
this.Dispose(false); | ||
} | ||
|
||
public override void Run() | ||
{ | ||
taskFunc.CallFunction(JavaScriptValue.GlobalObject); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
// We need to release the object so that the Chakra GC can reclaim it. | ||
taskFunc.Release(); | ||
|
||
base.Dispose(disposing); | ||
|
||
if (disposing) | ||
{ | ||
// No need to finalize the object if we've been disposed. | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ChakraCore Samples/JSRT Hosting Samples/C#/ChakraCoreHost/Tasks/TaskItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChakraCoreHost.Tasks | ||
{ | ||
public abstract class TaskItem : IDisposable | ||
{ | ||
public abstract void Run(); | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
} | ||
|
||
// This code added to correctly implement the disposable pattern. | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above. | ||
Dispose(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.