Giter Club home page Giter Club logo

Comments (2)

limebell avatar limebell commented on June 14, 2024 2

I guess #517 closes this issue.

from libplanet.

longfin avatar longfin commented on June 14, 2024

At first I thought to add the interface like below.

Task<Block<T>> Blockchain.MineBlockAsync(Address rewardBenficiary);
IEnumerator Blockchain.MineBlock(Address rewardBeneficiary, out Block<T> block); 
// or
IEnumerator Blockchain.MineBlock(Address rewardBeneficiary, Action<Block<T>> onMined); 

But there is some points to think about... (If I know something wrong, please comment.)

  • In Unity, we can use async / await. but there is no support like MonoBehaviour.StopCoroutine().
  • IEnumerator Blockchain.MineBlock() fits Unity's coroutine idiom perfectly. but making concurrency in this way seems to be Unity's style, not usual .NET style.
    • Nevertheless, if implemented in libplanet.net, we need to use Unity-dependent feature like WaitForSeconds.

We can still add an async / await style API, but it does not come up with any good utility right now.
Instead I suggest workaround for Unity like below

        public IEnumerator Mine(Address address)
        {
            while (true)
            {
                var task = Task.Run(() => blocks.MineBlock(address));
                yield return new WaitUntil(() => task.IsCompleted);
                Debug.Log($"mined {task.Result.Index}");
            }
        }

        private void Awake()
        {
             StartCoroutine(Mine(UserAddress));
        }

cc

@ipdae @kijun

from libplanet.

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.