Giter Site home page Giter Site logo

gimme's Introduction

Gimme

Gimme is an asyncronous resource loader for .NET

Nuget Package: LogicAndTrick.Gimme

Install-Package LogicAndTrick.Gimme

What's it do?

It's a very simple abstraction over resource providers. Conforming to an interface forces you to design your resource loaders in a particular way. Gimme prioritises asyncronous loading over everything else. Basically it's going to make it hard for you to do it the wrong way.

How do I use it?

First, write your resource provider. This is as simple as implementing any one of these interfaces:

  • ISyncResourceProvider<T> - A very simple provider that returns an IEnumerable<T>.
  • IAsyncResourceProvider<T> - A provider that returns a task that completes when all items are loaded. A callback is called for each resource that is loaded.
  • IObservableResourceProvider<T> - A provider that returns an IObservable<T> for those using Reactive Extensions or simply want a subscriber model.

Here's a basic resource provider that will return the numbers 0-9 as strings:

public class ExampleResourceProvider : SyncResourceProvider<string>
{
    // True if this class can provide the requested resource
    public override bool CanProvide(string location)
    {
        return location == "Example";
    }
    
    // Return the resource(s)
    public override IEnumerable<Thing> Fetch(string location)
    {
        for (var i = 0; i < 10; i++) yield return i.ToString();
    }
}

Next, tell Gimme about your resource provider. At application startup, register your providers:

Gimme.Register(new ExampleResourceProvider());
// ... and any others

Finally, request the resource. There are a few ways to do this:

  • IObservable<T> Gimme.Fetch<T>(string) - Request the resource as an observable
  • Task Gimme.Fetch<T>(string, Action<T>) - Request the resource as an async task
  • Task<T> Gimme.FetchOne<T>(string) - Request ONE item from a resource as a task and discard any others

This simple example will print the numbers 0-9 from our provider to the console (as long as you wait for the task to complete):

var task = Gimme.Fetch<string>("Example", r => {
    Console.WriteLine(r);
});

Why did you call it "Gimme"?

Because boring names are boring.

License

MIT

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.